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. Updating QLabel from non-gui thread

Updating QLabel from non-gui thread

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views
  • 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 Offline
    B Offline
    bagipro
    wrote on last edited by
    #1

    @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
    0
    • B Offline
      B Offline
      bagipro
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        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
        0

        • Login

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