QObject signal/slot not working
I have a class A that inherits QWidget and class B that inherits QObject.
When a button is clicked, class A creates an object of Class B. Class B is supposed to perform a http request and emit a done signal to perform the slot function.
The problem is that class B can initialize properly but it cannot execute the slot function when the done signal is emitted. As far as I know, I don't see debug errors and my actual code is a bit too long.
Example:
Code:
{
Q_OBJECT
public:
A();
private slots;
void buttonClicked();
private:
};
Code:
{
Q_OBJECT
public:
B();
private slots;
void performFunction();
};
Code:
A::A()
{
...
connect(button,SIGNAL(clicked()),this,SLOT(buttonClicked()));
void A::buttonClicked()
{
B objectB;
}
Code:
B::B()
{
...
connect(http,SIGNAL(done(bool)),this,SLOT(performFunction()));
}
Could anyone point out what I have done wrong.
Re: QObject signal/slot not working
Wild guess...
Does the http object already exist when this is executed:
connect(http,SIGNAL(done(bool)),this,SLOT(performF unction()));
Re: QObject signal/slot not working
Yes, I have created the object.
Oddly enough, when I try to create a class B object manually on the main function, the performFunction slot does execute normally.
Re: QObject signal/slot not working
Quote:
Originally Posted by
Msnforum
Code:
void A::buttonClicked()
{
B objectB;
}
Notice that "objectB" goes out of scope according to normal C++ rules and gets destructed immediately after its constructor has been executed.
Re: QObject signal/slot not working
Thanks, got that out of the way and the function does execute now.
Code:
B *objectB;
objectB = new B;
I've got another question, how would i proceed if i want to change the text of the button in class A.
If I inherit QObject and class A to access the button, it says QObject is already a base class of class A.
Edit: Compile just fine after removing QObject from inheritance leaving behind single inheritance to class A. The QPushButton text doesn't refresh though. Am I doing it right?