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. Update a QStatusBar located in another class with information in a for loop
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • F Offline
    F Offline
    fs_tigre
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      drhalftone
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fs_tigre
        wrote on last edited by
        #3

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

        Thanks a lot for your suggestion.

        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