How to inactivate qdialog



  • Hi,

    In my program I have 2 qdialogs. In first dialog when a certain push button is clicked I want to pop up the second dialog but at the same time I want to run the rest of the code in the first dialog.
    I did something like this in my first dialog box.

    @
    // code1
    Dialog2 *d11=new Dialog2();
    d11->exec();
    // code2
    @

    But when it is running the 2nd dialog appears and the code beyond the originating of 2nd dialog (code2) doesn't run. What should I do in order to pop up 2nd dialog and be inactive during the execution?



  • when you run exec() it wait's for you to close (accept, cancel or actually close) the dialog, so maybe you could run your code before exec() or use show() instead of exec()



  • I think you are looking for the open() or show() methods instead, depending if you want to have the second window behave like a modal or a non-modal window.



  • Hi,

    I tried in that way using show(). But then the 2nd dialog appears after executing the entire code. (after executing code2)



  • open() also doesnt seem to be working



  • Yes, that is true. The point is, that in order for Qt to be able to handle drawing windows, it needs the eventloop to run. And while your code is running, the eventloop is not. Could you tell us a bit more on what you want to achieve exactly? Are you running some long operations that you want to show progress on, perhaps?



  • Hi Andre,

    Actually I want to copy a selected file from one location to another. I am using qfilesystem for file navigation and once a file is selected and click the copy button the content must be copied.
    In this program up to the code1 I am doing file navigation and then the dialog2 must be appeared. then I execute copy command (command2)using qprocess:execute(cp,..).after the copying is completed the 2nd dialog must be closed. I am doing it using d11.close().

    thank you.



  • In that case, I have two suggestions that you can think about:

    Use the non-static methods of QProcess instead, and use the asynchronous methods (that is: connect to the finished() and other signals instead of using the waitFor* methods). That way, you will return to the eventloop as needed and everything will go smoothly. You can use the QProcess::finished() signal to close the second dialog.

    Implement your own file copying. This one is more tricky, but allows for greater control. You still need to make sure to return to the eventloop regulary during the copy process, either by doing the work in chunks or by using one of the multi-threading options.

    I think method 1 is easiest for now, and probably sufficient for your needs.



  • Hi,

    First of all sorry for delay reply. As you said I did something like following.

    @
    //code1
    Dialog2 *d11=new Dialog2();
    d11->open();
    QProcess *myprocess =new QProcess();
    myprocess->execute("cp", args);
    connect(myprocess,SIGNAL(finished(int)),d11,SLOT(close1()));
    @

    And in my Dialog2, I wrote close1() as follow

    @
    close1()
    {
    this.close();
    }
    @

    but the second dialog doesn't appear at the beginning of the copy process and also it doesn't close after copletion of the copy process. What I am missing here?

    thanks a lot.

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • sorry the connect method is as follow.
    connect(myprcocess,SIGNAL (finished(int)),d11, SLOT (close1()))


Log in to reply
 

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