Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Updating QLabel from non-gui thread

    General and Desktop
    2
    3
    1241
    Loading More Posts
    • 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.
    • B
      bagipro last edited by

      @void MainWindow::update()
      {
      while(work)
      {
      QSettings setting("Log.ini",QSettings::IniFormat);
      setting.beginGroup("History");
      setting.setValue("CurrentMailpass",currentDataLine);
      setting.endGroup();

          ui->label_21->setNum(socksLenght);
          ui->label_22->setNum(dataLenght);
          ui->label_23->setNum(currentSocksLine);
          ui->label_24->setNum(currentDataLine);
          ui->label_5->setNum(liveNum);
          QCoreApplication::processEvents();
      
          ::Sleep(2000);
      }
      

      }@

      @ QString key = ui->lineEdit_7->text();
      work = true;
      if(key.length() > 0) QtConcurrent::run(this,&MainWindow::socksUpdate,key);
      QtConcurrent::run(this,&MainWindow::update);
      thread();
      work = false;@

      But those labels are not updated

      1 Reply Last reply Reply Quote 0
      • B
        bagipro last edited by

        Lol i have 5 threads in the program, but 2 was runned only

        Fix:
        @QThreadPool::globalInstance()->setMaxThreadCount(100);@

        1 Reply Last reply Reply Quote 0
        • JKSH
          JKSH Moderators last edited by

          FYI, QWidgets are not thread safe, and should be accessed from the GUI thread only. Updating them directly from other threads can cause problems for you in the future.

          For cross-thread communications, I recommend signals + slots.

          Also, QtConcurrent::run() and QThreadPool are meant for short tasks (the whole idea is, when your task finishes, the thread can be reused for other tasks). For long tasks like infinite loops, use QThread.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply Reply Quote 0
          • First post
            Last post