Question

I'm selecting and loading some big Dicom files on my program. The whole loading process takes a long time(depends on the number of files, but the whole process can take more than minutes if the files are many). I want show a "waiting symbol" or something like that when the file uploading is going on. I searched for it, but I didn't get anything definite.

My code for the selection and uploading part is as below:

void MainWindow::showTheSelectedList()
{
    QFileDialog * fileDialog = new QFileDialog(this);

    fileDialog->setFileMode(QFileDialog::ExistingFiles);
    QListView* list = fileDialog->findChild<QListView*>("listView");
    if(list)
    {
        list->setSelectionMode(QAbstractItemView::MultiSelection);
    }
    QTreeView* tree = fileDialog->findChild<QTreeView*>();
    if(tree)
    {
        tree->setSelectionMode(QAbstractItemView::MultiSelection);
    }
    if(fileDialog->exec())
    {
        if(fileDialog->selectedFiles().size()>0)
        {

            int listsize=stringList.size();
            for(int i=0;i<listsize;i++)
            {
      //          get the name of the file
        //        check if the file is dicom
          //      upload if the file is dicom
            //    after uploading, get the pixel data of that file
              //  use the pixel data and make a icon out of it
                //then insert the icon in an a QTablewView
            }
        }
    }
    //show the QtableView
}

Could you please instruct me where and how I can show the waiting sign or symbol while the uploading part is running?

Thanks

Was it helpful?

Solution

I think you are looking for the QProgressBar class. The documentation makes it clear below. You will need to set up the minimum and maximum values, and it will do the job for you.

The QProgressBar widget provides a horizontal or vertical progress bar.

A progress bar is used to give the user an indication of the progress of an operation and to reassure them that the application is still running.

The progress bar uses the concept of steps. You set it up by specifying the minimum and maximum possible step values, and it will display the percentage of steps that have been completed when you later give it the current step value. The percentage is calculated by dividing the progress (value() - minimum()) divided by maximum() - minimum().

You can specify the minimum and maximum number of steps with setMinimum() and setMaximum. The current number of steps is set with setValue(). The progress bar can be rewound to the beginning with reset().

If minimum and maximum both are set to 0, the bar shows a busy indicator instead of a percentage of steps. This is useful, for example, when using QNetworkAccessManager to download items when they are unable to determine the size of the item being downloaded.

I do not think much more details can be provided based on the question as the worker loop seems to be commented without actual code being provided in there, but this documentation should make it clear either way.

Note that I would personally even move the worker loop into an own worker thread if it is that hefty that it deserves a progressbar. As for the progressbar, you would probably write something like this:

QProgressBar bar(this);
bar.setRange(maximum, maximum);
bar.setValue(minimum);
bar.show();

OTHER TIPS

Dialog box:

My novice suggestion would be to use progress bar inside your for loop and increment the progress bar as each file finishes loading.

Let me know if you need more detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top