2

I'm in the process of trying to figure out how to launch a windows application in Qt. What I'm trying to accomplish is for the user to click on a button and the notepad windows application opens. I understand that their is a notepad feature in Qt, but I looking for a different way to do this. I want to possible be able to do this with any windows application. Does anyone have any hint on how I can accomplish this?

Lukas Eklund
  • 6,068
  • 1
  • 32
  • 33
user3878223
  • 441
  • 3
  • 7
  • 15

2 Answers2

5

Qt has special class QProcess which allows you to do this.

For example:

void MainWindow::on_pushButton_clicked()
{
    QProcess *proc = new QProcess(this);
    proc->start("notepad.exe");
}

There are many useful methods in this class. Check it in the documentation:

http://qt-project.org/doc/qt-5/QProcess.html

Also you can open file in this app. Just use:

proc->start("notepad.exe path"); 

where path is something like this: G:/test.txt

To use this class you should #include <QProcess>

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • Is there some sort of include required for Qprocess? I'm getting errors. Thanks for your input – user3878223 Sep 23 '14 at 15:58
  • @user3878223 Oh, sorry, yes you need do include, I already updated my answer, see it please. – Jablonski Sep 23 '14 at 16:00
  • Never mind I found the include after looking at the link you posted. It giving me an error though. Is this familiar to you? :-1: error: LNK1123: failure during conversion to COFF: file invalid or corrupt – user3878223 Sep 23 '14 at 16:03
  • Never mind I found the include after looking at the link you posted. It giving me an error though. Is this familiar to you? :-1: error: LNK1123: failure during conversion to COFF: file invalid or corrupt – user3878223 Sep 23 '14 at 16:06
  • @user3878223 No, I'm not familiar with this, because I use Qt Creator IDE, your error looks like Visual Studio error only, so I can suggest you to google this problem. There are useful links: famous answer with 428 upvotes: http://stackoverflow.com/questions/10888391/error-link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-inval and some site: http://howtofix.pro/fixedfatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-corrupt/ – Jablonski Sep 23 '14 at 16:09
  • Actually I am using the Qt creator IDE, but thanks for your help – user3878223 Sep 23 '14 at 16:11
  • @user3878223 I understood, so try this http://stackoverflow.com/questions/22069551/error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-corrupt-in-qt `QMAKE_LFLAGS += /INCREMENTAL:NO` in the `file .pro` – Jablonski Sep 23 '14 at 16:13
  • Its continuing to give the same error when placing it in the .pro file – user3878223 Sep 23 '14 at 16:20
3

You can use QProcess class, look at start or startDetached, example:

QProcess::startDetached("notepad.exe");
Zlatomir
  • 6,964
  • 3
  • 26
  • 32
  • I'm getting the same error I did when trying the answer above :-1: error: LNK1123: failure during conversion to COFF: file invalid or corrupt – user3878223 Sep 23 '14 at 16:08
  • What visual studio version do you use? This seems to be an issue with VS2010 after you install .Net framework 4.5 and the solution is to update to VS2010 SP1: http://support.microsoft.com/kb/2757355 – Zlatomir Sep 23 '14 at 17:22
  • I'm actually using the QT Creator – user3878223 Sep 23 '14 at 18:04
  • I wasn't clear enough, so the question is what C++ compiler do you use? QtCreator is the IDE, and that has to use a compiler to build the code. The error suggest that you use a version of Visual C++ compiler. – Zlatomir Sep 23 '14 at 18:10
  • I just downloaded the software for QT. I used visual studios in college and it isn't currently installed on this computer. Maybe the compiler that QT uses is visual studios, I'm not sure honestly. – user3878223 Sep 23 '14 at 18:26
  • Open QtCreator, from _Tools_ menu open _Options_, select _Build and run_, select the kit you are using and see what c++ compiler is that kit using. – Zlatomir Sep 23 '14 at 19:43
  • @Zaltomir It says Desktop Qt 5.3 MSVC2010 OpenGL 32bit – user3878223 Sep 24 '14 at 12:09
  • ok, you use the C++ compiler that comes with VS2010, so according to microsoft support the resolution is to update visual studio to sp1 (the link posted earlier: http://support.microsoft.com/kb/2757355 ) – Zlatomir Sep 24 '14 at 12:13
  • If you don't have _Visual Studio_ installed, the C++ compiler can be installed with the _Windows SDk_, so in that case you need to search the Windows SDK update that contains the vc++ 10 service pack 1 compiler (my guess is that Windows SDK 7.1 should be a good starting point, but i'm not sure, so you must search that information) – Zlatomir Sep 24 '14 at 12:24
  • I got it working. I just "cleaned" the program and for some reason it worked after that. I have NO idea why. – user3878223 Sep 25 '14 at 12:20