Runtime error on connect



  • I've been trying to connect a signal to a slot and it compiles but once the connect function is run the program the thread gets stuck processing connect for maybe one second before crashing. I must be calling the connect error incorrectly but I can't figure out how. I've included the relevant sections of code below.

    @
    //It runs until the connect function but never reaches the debug code.
    void MainWindow::importThreads(TimerThread* t, AiThread* a){
    worker = t->getThread();
    aiThread = a;
    connect(worker,SIGNAL(timeout()),this,SLOT(refreshPosition()));
    qDebug() << "Connected!";
    }

    //This is the slot. This code is never run.
    void MainWindow::refreshPosition(){
    ui->xPositionDisplay->display(getXPosition());
    ui->yPositionDisplay->display(getYPosition());
    ui->headingAngleDisplay->display(getHeading());
    }
    //Declaration of Signal in Worker class
    signals:
    void timeout();

    //Declaration of slot in the MainWindow class
    public slots:
    void refreshPosition();
    @



  • You don't run MainWindow in a thread other than main, right?
    What is value of worker? Can it be nullptr?



  • You were right about the worker object being a invalid. It turns out the worker pointer in timer thread had yet to be initialized. Thanks.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.