c++ - QT : Passing QString to QThread -
i want pass qstring
thread.using this answer, here code: in mainwindow.cpp:
mmthread = new mythread; mmthread->start(); connect(this,signal(sendtothread(qstring)),mmthread,slot(getfrom_main(qstring)),qt::queuedconnection); emit sendtothread(mystr);
in mainwindow.h:
signals: void sendtothread(qstring);
in mythread.cpp:
void mythread::getfrom_main(qstring str) { //something }
in mythread.h:
public slots: void getfrom_main(qstring);
but seems getfrom_main
not called @ all. mistake?
edit:
i have 3 similar threads this:
in mythread.cpp:
mythread :: mythread() { movetothread(this); } void mythread::run(){ //something1 } void mythread::getfrom_main(qstring comm) { comment = comm; emit message(comment); }
in mythread.h:
class mythread : public qthread { q_object public: explicit mythread(); void run(); signals: void message (qstring); private: qstring comment; public slots: void getfrom_main(qstring); };
something1
executes in threads.but not getfrom_main
.thanks.
wrong:
mythread :: mythread() { movetothread(this); // don't need }
wrong (you don't need inherit qthread
in code):
void mythread::run() { //something1 // after "something" need run event loop: exec(); }
exec()
run event loop process signals , slots.
Comments
Post a Comment