0

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
user2235370
  • 51
  • 1
  • 1
  • 4
  • So can you see Initialising When slot end execute? If so, then probably you block GUI thread and should show full code of this slot – Jablonski Jan 03 '15 at 05:46
  • nope, i can never see the string set in slotButtonConnectClicked() even after the slot function has returned (ive checked, using the debugger)! my code makes calls to dll there, but it returns as expected. – user2235370 Jan 03 '15 at 09:24
  • if i comment out my code, the example works as expected. so i somehow must be blocking the gui thread i guess... it is some usb driver communication, cant post full code – user2235370 Jan 03 '15 at 09:37

0 Answers0