Object from QToolbar in a QWidget
-
Hello, I designed a class which inherit from QToolBar. At this Toolbar there is a Button.
Now I add this Toolbar to a QWidget, but if I click on the Button at the Toolbar nothing happens. Why is the Signal not send to the Toolbar? -
Hi, what signal do you expect it to send ?
Did you connect button and toolbar ?
Normally you would use QActions and pressing button would activate the action. -
@mrjj in the class which inherit from QToolBar is the Button "home". I wrote this: connect(home, SIGNAL(released(void)), this, SLOT(clickHome(void)));
If I click on the Button in my Widget nothing happens. -
@Michelle02283
did you check that connect returns true ?
To check connection can be made.
maybe remove the void and just have released() and clickHome() -
@mrjj I tried with a QDebug if something happens, but nothing happens.
-
@Michelle02283
did you try
qDebug() << "can conn:" << connect(home, SIGNAL(released()), this, SLOT(clickHome()));
and see it says true ?Also do you have Q_OBJECT
in your toolbar subclass ? -
@mrjj
No, it says nothing.No I have no Q_OBJECT in my subclass. Why do I need it? I tried to add it, but I got an error.
-
@Michelle02283
if it says nothing, then the connect is NOT executed ??Yes, you need Q_OBJECT in your class
like
class HeightMap : public QWidget {
Q_OBJECT
..its good idea to delete all in build folder so u are sure its all rebuild after adding this macro.
-
@mrjj the Q_OBJECT was the problem. I added it and now it works.
Thanks.