I am just starting out with Qt (5.4 to be precise), using it to build a GUI for a C++ project to control some hardware.
Now my problem is, I cant update any QLineEdit
(or QLabel
, but this seems to be the same problem) text displayed using its setText()
method. By 'update' I mean it works once when called from the main window constructor but then no more.
I am using setText()
from within the slot functions I defined. Even using repaint()
right afterwards didn't do anything.
I must be doing something horribly wrong here...
Update: this is indeed correct, my own code is causing problems with GUI thread
Here is an example
main.cpp
int main( int argc, char* argv[] ) {
QApplication app(argc, argv);
CmainWindow mainApp;
mainApp.show();
return app.exec();
}
CMainWindow.h
class CMainWindow : public QMainWindow, private Ui::MainWindow {
Q_OBJECT
Q_DISABLE_COPY( CMainWindow )
public:
CMainWindow( QWidget *parent = 0 );
~CMainWindow();
public slots:
void slotButtonConnectClicked(void);
protected:
void setConnections();
private:
AbstractReader_t* pReader;
QString* ErrorString; // conversion mule for std::string
);
CMainWindowConnections.cpp
void CMainWindow::setConnection(void) {
Q_CHECK_PTR( pushButton_Connect )
connect( pushButton_Connect, SIGNAL( clicked() ), this, SLOT( slotButtonConnectClicked()) );
}
CMainWindow.cpp
CMainWindow::CMainWindow( QWidget *parent ) : QMainWindow(parent) {
pReader = NULL;
ErrorString = new QString("GUI Initialized"); // just something to test
setupUi(this);
setConnections();
lineEdit_Error->setText(*ErrorString); // this works !
}
void CMainWindow::slotButtonConnectClicked( void ) {
lineEdit_Error->setText("Initialising..."); // this wont show
// some of my own code here caused problem
} //nope, not even after here