connect(pushButton, SIGNAL(clicked()), this->parent(), SLOT(slot_pushButton()));
this->parent() is the problem .. the third argument
make just this ..
connect(pushButton, SIGNAL(clicked()), this->parent(), SLOT(slot_pushButton()));
this->parent() is the problem .. the third argument
make just this ..
"Behind every great fortune lies a crime" - Balzac
I tried just "this" and it doesnt work.
If I make this->parent() I can AT LEAST connect it to the slot of the class Lines.
If I make only "this" nothing works at all.
The Dummy object is constructed and connects a clicked() signal to the slot_pushButton() of its parent() QObject. In the code we can see that would be an object of class Lines. That class does not have a slot called slot_pushButton() and you should be seeing a run time warning to that effect. Connections between QObjects are destroyed when the object at either end is destroyed but since this connection is never made...
If you connect to clicked() signal to the slot of the Dummy class, i.e. this, you will at least establish a connection (as wagmare points out). However, your Dummy object is created, constructed and destroyed in the space of one source code line. Connections between QObjects are destroyed when the object at either end is destroyed, in this case the Dummy object is destroyed. The push button widget itself only persists because you are parenting it to another widget that persists past the demise of Dummy.
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
wagmare (2nd September 2013)
I read your answer carefully, ChrisW67
and I think I understood it.
So it is simply not possible to do it the way I wanted, right??
uhmmm...
I tried something similar.
Instead of calling my Dummy class from the Constructor of the Line class,
I called my Dummy class from the main.
MainQt Code:
int main (int argc, char*argv[] ) { a.connect (&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); Lines w; Dummy d; w.show(); return a.exec();To copy to clipboard, switch view to plain text mode
If I do like this, I can use the Slots in the Dummy class, but I cannot paint the pushbutton from my Dummy class on the widget from my Mainclass.
Qt Code:
To copy to clipboard, switch view to plain text mode
Any Idea how to solve it?
This is what I want to achieve if you shouldnt understand me
4t2yahaa.jpg
http://s14.directupload.net/images/130902/4t2yahaa.jpg
![]()
Yes, make Dummy a QWidget and insert an instance of Dummy into the layout of the widget you wish to contain it. Just like every example in the Qt documentation.
uhmm, could you be so kind and explain me how to insert the instance?
It just crashes every time I reach the
"pushButton = new QPushButton(parent->widget_main);"
Bookmarks