Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QProgressDialog doubt

    General and Desktop
    5
    24
    17453
    Loading More Posts
    • 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.
    • G
      goetz last edited by

      No, you must start gui elements in the main thread.

      It depends on you application what to do exactly. If the app should block until the connection is done you can try something like this:

      @
      QProgressDialog pd;
      // setup the dialog like posted

      QEventLoop el;
      connect(&_tcpScoket, SIGNAL(connected()), &el, SLOT(quit()));

      QTcpSocket sock;
      connect(&_tcpScoket, SIGNAL(connected()), &pd, SLOT(cancel()));
      _tcpScoket.connectToHost("host", 80);
      el.run();
      pd.cancel();
      @

      This runs a local event loop, it keeps the QApplication running, but blocks the flow of control in the method until the socket is connected (and thus the event loop stops).

      You will have to add some error handling (eg. connect to the error signal of the socket) and/or add a QTimer to setup a timeout.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply Reply Quote 0
      • D
        dasmoeh last edited by

        I tried your code, but it did not work.
        The first shows only for a second a pop-up after it finished waiting.
        With the second i don't know where to call @_tcpScoket.waitForConnected(30000) @? I think el.run() should be el.exec()?

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

          Ahm. The progress dialog is only shown until the initial TCP connection has been set up. This usually takes less than a second on a decent internet connection... How long do you expect that to last in your case?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply Reply Quote 0
          • D
            dasmoeh last edited by

            Mh, i tried to connect to a not given IP. I want to see the dialog while
            @
            _tcpScoket.waitForConnected(30000)
            @
            is active till it times out. At 30000 ms.

            In not working code:
            @
            dlg.show()
            _tcpScoket.waitForConnected(30000)
            dlg.cancel()
            @

            But in this 30000ms i don't get updates to my gui. Like i expected. But i'm looking for a way, to have my progressdialog running during this 30000 ms without calling waitForConnected from another thread because i don't want to move my socket from the main thread.
            I think it's not possible?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post