Run an .exe from other's application function

  • Hi,

    I have created two different applications seperatly.A form named window and a form named my_mainwindow, and I want to run the window.exe when I call a press button function my_mainwindow application. I have written the following code, I debug my_mainwindow without any errors, but when I press the button I don't get my window form from the window.exe file.Also when I insert in my code the (system("pause");), when I press the button I get the cmd.exe .Could somebody help me?

    @QObject::connect(pushButton_openFile, SIGNAL(clicked()), this, SLOT(push_button_File()));@


    @void my_mainwindow::push_button_File(void)

    QProcess::execute("E:\Qt tutorial\Qt applications\window\window\window.exe");

    // system("pause");
    return ;

  • It likely has something to do with exe-file path. Try placing both EXE files in a same folder and use relative path... Also, why not make an instance of QProcess and use start() method as described "here":

  • I have moved both .exe files in the same directory and I have tried this, but with no any good result

    @void my_mainwindow::push_button_File(void)

    QString program = "E:\Qt tutorial\Qt applications\my_mainwindow\my_mainwindow\window.exe";
    QProcess *myProcess = new QProcess(this);
    myProcess->start(program, 0);

    return ;

  • You should also change path to "window.exe". Also, as a second argument you are suppling 0. Why? If you have no arguments to send try: myProcess->start(program). Furthermore you should listen "some of these signals": to make sure window.exe is running, closing etc.

  • To change path to "window.exe", this should be done from my project's properties, in my visual studio that I am using for the project?

  • No no, I was referring to:
    @QString program = "E:\Qt tutorial\Qt applications\my_mainwindow\my_mainwindow\window.exe";@
    It should be:
    @QString program = "window.exe";@

    Also, you should try to run both apps from outside the IDE. Navigate to folder and run both EXEs. This is to make sure apps are not missing any DLLs.

  • This was my mistake. I should have QString program = "window.exe"; in my code.
    Thanks a lot for your help.

  • And change the path separators from backslashes ("") to regular forward slashes ("/"). Qt does the translation for you and if you really want to use the, you must double quote them, as the C/C++ compiler interprets them as string specials (like "\n"):

    QString program = "E:/Qt tutorial/Qt applications/my_mainwindow/my_mainwindow/window.exe";

  • thanks for your reply

Log in to reply

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