Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Runtime error on connect
Qt 6.11 is out! See what's new in the release blog

Runtime error on connect

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meitme
    wrote on last edited by
    #1

    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();
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        meitme
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved