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.
{
Q_OBJECT
public:
A();
void clickPressed();
private slots:
void changeButtonText();
private:
};
A::A()
{
connect(button,SIGNAL(clicked()),this,SLOT(clickPressed()));
}
void A::changeButtonText()
{
button->setText(tr("again"));
}
void A::clickPressed()
{
B *objectB = new B;
}
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(clickPressed()));
}
void A::changeButtonText()
{
button->setText(tr("again"));
}
void A::clickPressed()
{
B *objectB = new B;
}
To copy to clipboard, switch view to plain text mode
class B : public A
{
Q_OBJECT
public:
B();
private slots:
void requestDone();
private:
};
B::B()
{
....
connect(http,SIGNAL(done(bool)),this,SLOT(requestDone(bool)));
}
B::requestDone(bool error)
{
...
changeButtonText();
}
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(requestDone(bool)));
}
B::requestDone(bool error)
{
...
changeButtonText();
}
To copy to clipboard, switch view to plain text mode
I wrote the above as an example to my problem.
Bookmarks