Update a QStatusBar located in another class with information in a for loop



  • Hi,

    I'm currently working on a program that searches for files and everything is working as expected but I would like to make one of the functions more modular. In other words I want to turn this program into a reusable class/utility so I can use it in multiple programs. Here is my issue, in a searching function I have a foreach and inside this foreach loop I'm showing the URLs of the searched files and folders on a QStatusBar, and again everything is working fine because the QStatusBar and the forearch are in the same program and the statusBar gets updated in every loop. What I want to do is basically be able to update a QStatusBar located OUTSIDE this class and be able to show the files and folders that are currently in search.

    What would be the logic I need to accomplish what I'm describing above? A getter to capture the changes? A signal and a slot?

    FYI,
    I tried the getter method but I only get the last searched URL.

    Here is a snippet of the code I'm talking about.

    @void MianWindow::searchFunction()
    {
    foreach( QString folder2, mainTargetDirectory.entryList(QDir::Dirs|QDir::NoDotAndDotDot) )
    {
    QFile nextFolder2 (mainTargetDirectory.absoluteFilePath(folder2)+ "/"+ fileToBeFound);
    // this is the line of code that I would like to make modular and be able to
    // update a QStatusBar located out side MainWindow.
    ui->statusBar->showMessage(mainTargetDirectoryPlus.absoluteFilePath(folder2)+ "/"+ fileToBeFound,5000);
    if(nextFolder2.exists())
    {
    found = true;
    break;
    }
    }
    }@

    I hope it make any sense.



  • Make a subclass of the status bar widget, and then add a slot that accepts a QString along with a percentage complete integer. Upgrade the widget in Qt designer to this new subclass. Now you can either call the function directly or set up a signal in our main window class and emit updates.



  • Wow, it's a little more complicated than what I thought but I will give it a try.

    Thanks a lot for your suggestion.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.