c++ - QT slots and signals fail -
hi there got problem signal , slots in qt. in main have created object of mainwindow. in mainwindow.cpp creating object of class(modbus_tcp). creating connection here
void mainwindow::on_connectb_clicked() { modbus_tcp appts; appts.slave(); connect(&appts,signal(msgsended(qstring)),this,slot(msgedit(qstring))); }
between slot declared in mainwindow.cpp/h
public slots: void msgedit(qstring m); void mainwindow::msgedit(qstring m) { ui->sendedit->settext(m); ui->recvedit->settext(m); //qmessagebox::information(0,"bad", "nope nope nope"); }
and signal declared in modbus_tcp.h
signals: void msgsended(qstring);
next emiting signal in modbus_tcp.cpp
emit msgsended("asdasd");
and nil happen
when trying emit in mainwindow.cpp working
any ideas ?
void mainwindow::on_connectb_clicked() { modbus_tcp appts; appts.slave(); connect(&appts,signal(msgsended(qstring)),this,slot(msgedit(qstring))); }
appts
created in stack, deleted @ end of slot execution. seek create in heap(try utilize pointer).
void mainwindow::on_connectb_clicked() { modbus_tcp *appts = new modbus_tcp; connect(appts,signal(msgsended(qstring)),this,slot(msgedit(qstring)));//first! appts->slave();//now can phone call }
use pointers, first of connect
, , after phone call slave
. emit signal in slave
, there no connection in time. should connection firstly , after that, able grab signals.
c++ qt signals connect slot
No comments:
Post a Comment