I want to convert a widget.cpp widget.h You are reaching Edit Based on your follow-up question, maybe you were looking for something like this? toStCent to another class
toInt , But it fails because the result is 0 while it should be 5 and the remaining code works. Because I'm new to C / QT and to confuse the classes a bit, I think I have done something wrong in my classes. Widget.cpp
#include "widget .h" #include "ui_widget.h" widget :: widget (QWidget * parent): QWidget (parent) UI (new Ui :: widget) {UI- & gt; SetupUi (this); } Widget :: ~ widget () {Delete UI; } Zero widget :: on_pushButton_clicked () {MyClass tmp; Int myNumber = tmp.m_replyStr.toInt (); UI- & gt; LcdNumber- & gt; Display (myNumber); } MyClass :: MyClass () {m_manager = New QNetworkAccessManager (this); Connect (M_Manager, Signal (Finished (QN NetworkCarP *)), This, Slot (Answer Finished (QN NetworkCar * *)); } Zero MyClass :: fetch () {m_manager- & gt; Get (QNetworkRequest (QUrl ("http: //example.tld/test.html"))); // html only numbers 5} zero MyClass :: replyFinished (QNetworkReply * pReply) {QByteArray data = pReply-> ReadAll (); Cue string straw (data); M_replyStr = str; }
#ifndef WIDGET_H #define WIDGET_H #include & lt; QWidget & gt; # Include & lt; QObject & gt; # Include & lt; QNetworkAccessManager & gt; # Include & lt; QUrl & gt; # Include & lt; QNetworkRequest & gt; # Include & lt; QNetworkReply & gt; Namespace UI {class widget; } Category Widget: Public QWidget {Q_OBJECT Public: Clear Widget (QWidget * parent = 0); ~ Widget (); Private slot: zero on_pushButton_clicked (); Private: UI :: Widget * UI; }; Class MyClass: Public QObject {Q_OBJECT Public: MyClass (); Get zero (); QString m_replyStr; Public slots: zero answer expired (QNetworkReply *); Private: QNetworkAccessManager * m_manager; }; #endif // WIDGET_H
m_replyStr There is a new starting example
TMP , which does not set anything in its
m_replyStr , then it has the default-initial value of "empty string".
Class MyClass; Class widget: public QWidget {Q_OBJECT public: widget (MyClass & myClassInstance, QWidget * parent = 0); ~ Widget (); Private slot: zero on_pushButton_clicked (); Private: UI :: Widget * UI; MyClass * myClass; }; Widget :: Widgets (Myclass and MyClass Instance, QWidget * parent = 0): QWidget (UI), UI (new Ui :: widget), myClass (and myClassInstance) (UI-> setupUi (this);} zero Widget :: on_pushButton_clicked () {int myNumber = myClass-> m_replyStr.toInt (); UI-> LCDNumber-> Display (myNumber);} < / Html>
No comments:
Post a Comment