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. QProgressDialog doubt
Forum Updated to NodeBB v4.3 + New Features

QProgressDialog doubt

Scheduled Pinned Locked Moved General and Desktop
24 Posts 5 Posters 21.0k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #21

    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
    0
    • D Offline
      D Offline
      dasmoeh
      wrote on last edited by
      #22

      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
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #23

        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
        0
        • D Offline
          D Offline
          dasmoeh
          wrote on last edited by
          #24

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved