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. QProgressDialog not displayed

QProgressDialog not displayed

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 731 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.
  • R Offline
    R Offline
    robcont_
    wrote on last edited by robcont_
    #1

    Hi,
    I have a TaskManager that has to perform some long operation. Since the operation has not a fixed duration I want a QProgressDialog to be displayed with an undefined progress bar.
    Below is my code but it does not work: the dialog is not displayed. Where am I doing wrong?

    auto response = QMessageBox::question(this, "Confirm", "Are you sure you want to install?");
    if (response == QMessageBox::StandardButton::Yes) 
    {
        QProgressDialog progress("Installing...", "Abort", 0, 0, this);
        progress.setWindowModality(Qt::WindowModality::WindowModal);
        progress.show();
    
        QThread *thread = new QThread(this);
        TaskManager *task = new TaskManager();
        task->moveToThread(thread);
    
        connect(task,   &TaskManager::installed, task,      &TaskManager::deleteLater);
        connect(task,   &TaskManager::installed, thread,    &QThread::quit);
        connect(task,   &TaskManager::installed, &progress, &QProgressDialog::close);
        connect(thread, &QThread::started,       task,      &TaskManager::install);
        connect(thread, &QThread::finished,      thread,    &QThread::deleteLater);
        
        thread->start();
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Best guess is that the variable
      QProgressDialog progress;
      is deleted very soon as the function ends.
      so even thread lives, the actual QProgressDialog does not.

      try
      QProgressDialog *progress = new QProgressDialog("Installing...", "Abort", 0, 0, this);

      R 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        Best guess is that the variable
        QProgressDialog progress;
        is deleted very soon as the function ends.
        so even thread lives, the actual QProgressDialog does not.

        try
        QProgressDialog *progress = new QProgressDialog("Installing...", "Abort", 0, 0, this);

        R Offline
        R Offline
        robcont_
        wrote on last edited by
        #3

        @mrjj said in QProgressDialog not displayed:

        Hi
        Best guess is that the variable
        QProgressDialog progress;
        is deleted very soon as the function ends.
        so even thread lives, the actual QProgressDialog does not.

        try
        QProgressDialog *progress = new QProgressDialog("Installing...", "Abort", 0, 0, this);

        Thanks it works! It was a very simple solution.

        1 Reply Last reply
        1

        • Login

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