c++ - SIGNAL fail when debug started -
i have issue using connection stuff of qt5. posted here code give quick view:
void mainwindow::onmessage(const message* message) { try { const textmessage* textmessage = dynamic_cast<const textmessage*> (message); std::string text = ""; if (textmessage != null) { text = textmessage->gettext(); } else { text = "not textmessage!"; } int fieldindex=message->getintproperty("field"); qstring qstr = qstring::fromstdstring(text); switch(fieldindex) { case 0:ui->lineedit->settext(qstr);break; case 1:ui->lineedit_2->settext(qstr);break; case 2:ui->lineedit_3->settext(qstr);break; case 3:ui->lineedit_4->settext(qstr);break; case 4:ui->lineedit_5->settext(qstr);break; case 5:ui->lineedit_6->settext(qstr);break; case 6:ui->lineedit_7->settext(qstr);break; case 7:ui->lineedit_8->settext(qstr);break; case 8:ui->lineedit_9->settext(qstr);break; } connect(ui->lineedit_4,signal(textchanged(qstr)),ui->widget_diagram2,slot(updatedatas(qstr))); }catch (cmsexception& e) { e.printstacktrace(); } } as can see i'm trying connect signal textchanged generated lineedit_4 ui object widget_diagram2 , execute slot updatedatas(qstr). bad happens, because received message:
qobject::connect: no such signal qlineedit::textchanged(qstr) in mainwindow.cpp:97 qobject::connect: (sender name: 'lineedit_4') qobject::connect: (receiver name: 'widget_diagram2') personally don't know why....where error?
void mainwindow::updatedatas(qstring qstr){ bool ok; double value0=qstr.todouble(&ok); double key = qdatetime::currentdatetime().tomsecssinceepoch()/1000.0; static double lastpointkey = 0; if (key-lastpointkey > 0.01) // @ add point every 10 ms { ui->widget_diagram2->graph(0)->adddata(key, value0); ui->widget_diagram2->graph(0)->removedatabefore(key-8); ui->widget_diagram2->graph(0)->rescalevalueaxis(); lastpointkey = key; } ui->widget_diagram2->xaxis->setrange(key+0.25, 8, qt::alignright); //ui->widget_diagram2->replot(); } and error:
qobject::connect: no such slot qcustomplot::updatedatas(qstring) in mainwindow.cpp:97 qobject::connect: (sender name: 'lineedit_4') qobject::connect: (receiver name: 'widget_diagram2') .h file:
#ifndef mainwindow_h #define mainwindow_h #include <qmainwindow> #include <qtimer> #include <activemq/library/activemqcpp.h> #include <decaf/lang/thread.h> #include <decaf/lang/runnable.h> #include <decaf/util/concurrent/countdownlatch.h> #include <decaf/lang/integer.h> #include <decaf/lang/long.h> #include <decaf/lang/system.h> #include <activemq/core/activemqconnectionfactory.h> #include <activemq/util/config.h> #include <cms/connection.h> #include <cms/session.h> #include <cms/textmessage.h> #include <cms/bytesmessage.h> #include <cms/mapmessage.h> #include <cms/exceptionlistener.h> #include <cms/messagelistener.h> #include "qcustomplot.h" #include "ifacomamqreceiver.h" namespace ui { class mainwindow; } class mainwindow : public qmainwindow, public messagelistener { q_object public: explicit mainwindow(qwidget *parent = 0); ~mainwindow(); void connectionreceiver(); void onmessage(const message*); void setupdiagram(); ifacomamqreceiver* m_ifacomamqlistener; private: ui::mainwindow *ui; private slots: void updatedatas(qstring); }; #endif // mainwindow_h
you call connect() wrong. should be:
connect(ui->lineedit_4, signal(textchanged(qstring)), ui->widget_diagram2, slot(updatedatas(qstring))); pay attention inside connect should pass types rather variables names. constant references const type & ok, ideally should elided yield type - saves on typing, , connect internally anyway.
Comments
Post a Comment