Msnforum
27th January 2009, 23:00
I have two classes: class A and B. class A inherits QWidget and class B inherits class A.
When a button is clicked, it connects to a slot in class A that creates an object of class B.
After the http request is done in class B, it executes a function from the base class that changes the text of the button.
Everything runs except the button doesn't update at all. qDebug shows the label as the new text but on GUI, it is still displaying the old text. I tried update() and repaint() but none works.
class A : public QWidget
{
Q_OBJECT
public:
A();
void clickPressed();
private slots:
void changeButtonText();
private:
QPushButton *button;
};
A::A()
{
button = new QPushButton(tr("Hello"));
connect(button,SIGNAL(clicked()),this,SLOT(clickPr essed()));
}
void A::changeButtonText()
{
button->setText(tr("again"));
}
void A::clickPressed()
{
B *objectB = new B;
}
class B : public A
{
Q_OBJECT
public:
B();
private slots:
void requestDone();
private:
QHttp *http;
};
B::B()
{
http = new QHttp(this);
....
connect(http,SIGNAL(done(bool)),this,SLOT(requestD one(bool)));
}
B::requestDone(bool error)
{
...
changeButtonText();
}
I wrote the above as an example to my problem.
When a button is clicked, it connects to a slot in class A that creates an object of class B.
After the http request is done in class B, it executes a function from the base class that changes the text of the button.
Everything runs except the button doesn't update at all. qDebug shows the label as the new text but on GUI, it is still displaying the old text. I tried update() and repaint() but none works.
class A : public QWidget
{
Q_OBJECT
public:
A();
void clickPressed();
private slots:
void changeButtonText();
private:
QPushButton *button;
};
A::A()
{
button = new QPushButton(tr("Hello"));
connect(button,SIGNAL(clicked()),this,SLOT(clickPr essed()));
}
void A::changeButtonText()
{
button->setText(tr("again"));
}
void A::clickPressed()
{
B *objectB = new B;
}
class B : public A
{
Q_OBJECT
public:
B();
private slots:
void requestDone();
private:
QHttp *http;
};
B::B()
{
http = new QHttp(this);
....
connect(http,SIGNAL(done(bool)),this,SLOT(requestD one(bool)));
}
B::requestDone(bool error)
{
...
changeButtonText();
}
I wrote the above as an example to my problem.