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. Pop up a progress bar on a pushed button (QML)

Pop up a progress bar on a pushed button (QML)

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.3k 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.
  • A Offline
    A Offline
    Alex11
    wrote on last edited by
    #1

    Hey guys,

    I have a problem with a progress bar in QML. Here is my QML file.

    import QtQuick.Controls 1.4
    
    Rectangle {
        id:root
        width: 500
        height: 550
        Launcher {
            id: launcher
        }
    
        Button {
            x: 125
            y: 400
            width: 262
            height: 45
            text: "Start"
            onClicked: {
                popup.open();
                launcher.open_terminal();
            }
            anchors.horizontalCenter: parent.horizontalCenter
        }
    
        Button {
            x: 125
            y: 450
            width: 262
            height: 45
            text: "Close"
            onClicked: {
                Qt.quit()
    
            }
    
            //highlighted: true
            anchors.horizontalCenter: parent.horizontalCenter
        }
        Image {
            anchors.horizontalCenter: parent.horizontalCenter
            source: "index.png"
        }
    
        Popup {
            id: popup
            ProgressBar {
                id: pb1
                minimumValue: 0
                maximumValue: 100
                value: 0
            }
    
            // Timer to show off the progress bar
            Timer {
                id: simpletimer
                interval: 100
                repeat: true
                running: true
                onTriggered: pb1.minimumValue < pb1.maximumValue ? pb1.value += 1.0 : pb1.value = pb1.value
            }
        }
    }
    

    Is very simple., "launcher.open_terminal();" run an external C++ executable. The problem is when i push the button the external executable start and after he is done the job the progress bar start. I wold like first to start the progress bar and after that the executable. Has anyone any idea how can i do this? So maybe a better idea then "popup". (i couldn't find other better solution)
    Thank you. :)

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Can you show the body of Launcher::open_terminal()?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alex11
        wrote on last edited by
        #3

        Sore, here it is

        void TerminalLauncher::open_terminal() {
            this->proc.start("C:\\Windows\\System32\\calc.exe", QIODevice::ReadWrite);
            this->proc.waitForFinished(-1);
        }
        
        jsulmJ 1 Reply Last reply
        0
        • A Alex11

          Sore, here it is

          void TerminalLauncher::open_terminal() {
              this->proc.start("C:\\Windows\\System32\\calc.exe", QIODevice::ReadWrite);
              this->proc.waitForFinished(-1);
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Alex11 said in Pop up a progress bar on a pushed button (QML):

          this->proc.waitForFinished(-1);

          No wonder it does not work as you're waiting for the process to finish!
          Why do you wait? Just remove that line.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • A Offline
            A Offline
            Alex11
            wrote on last edited by
            #5

            I can not do that because here calc.exe is just an example. In place of calc.exe i have my own executable and i need to wait until he finish because he write data in a xml file, and when he finish writing i lunch a new qml page with data from xml.
            So i need to find a way that my external process to run until he finish and in the some time to start also the progress bar. Maybe with a new thread or something like this but i cannot find a way yet.

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              Do not use the Sync API, connect a slot to the QProcess::finished signal to know when the process is done writing the xml and remove the waitForFinished

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3
              • A Offline
                A Offline
                Alex11
                wrote on last edited by
                #7

                ok, i will try to give a shut. I will came back with a result. Until now i can not fix it yet.

                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