1
votes

I am new to QT and C++ and i have legacy qt-c++ code here which i cant get to work. Probably its something about the lifetime of the calling objects but hey, but please tell me what i am missing.

In a QT .ui i have various Frames and Widgets containing Frames and Widgets containing a QVBoxLayout which we shall call "myLayout"

On click in the .ui file i use

myWidget = new mywidget(some params);
myLayout->addWidget(myWidget);

where myWidget is declared as mywidget *myWidget; in the header file

myWidget is a QWidget which internally adds a QVBoxLayout to itself and adds a QGraphicsView. Using the MouseReleaseEvent i emit a signal from the QWidget.

now when i try to connect the signal slot (which i do in cpp file from the ui)

connect(myWidget, SIGNAL(mySignal(QString)), this, SLOT(mySlot(QString)));

the signals never catch the slot. the slot is public, the signal isnt.

What did i do wrong? Can somebody help. Feel free to ask further questions since i dont really know whats important in c++ questions;)

edit: the signal gets emitted by QGraphicsObjects which themselfs connect to a slot in the QGraphicsView. This Slot is called and debuggable. at the end of the Routine an emit mySignal("..."); is called.

1
Did you make sure that the signal is emitted? Does your connect statement return true?thuga
Are you sure that you emit signal mySignal? Please, show the code of MouseReleaseEvent. Maybe it does not work?Kirill Chernikov
when debugging, emit mySignal("xxx"); is getting called. thanks for the hint that connect can return true, i tested an yes it returns true.efkah
And what about Q_OBJECT macro? Do you add it in widget declaration?Kirill Chernikov

1 Answers

2
votes

Maybe you forgot to add Q_OBJECT macro in your widget declaration. Qt documentation: http://doc.qt.io/qt-5/qobject.html#Q_OBJECT