PDA

View Full Version : Using Creator to create standard console applications



seux
4th September 2011, 22:09
Hey,
I was just wondering if i can also use the Qt Creator to code standard console applications. I tried it with just an hello world app

#include <iostream>
using namespace std;

int main(void)
{
cout << "Hello World";
return 0;
}
and it compiled fine. But when i start the .exe its says that various .dll's are needed to run it which makes not much sense. So, do i have to to check something that it compiles without Qt stuff, or is it not possible?

bah
4th September 2011, 23:15
Hello, I understand you used qmake. Did you remember to edit your project file (.pro) to exclude linking rules and include paths related to Qt ? Something like:

CONFIG -= qt

seux
5th September 2011, 13:07
No, I did not, but the idea points probably in the right direction :)
I tried

CONFIG -= qt
and

CONFIG -= qt
CONFIG += console

But both worked not, my application is still not running :(

bah
5th September 2011, 15:21
Does it complain about Qt dlls or compiler related dlls? If you compiled using mingw it will require both the mingwm10 and the libgcc dlls (I'm assuming from your post you're under Windows) and similar requirements should be met with MSVC. You should do a static compile to deploy a single .exe file (I'm not sure about the licensing implications of such, though). Should you decide to keep linking dynamically, you should deploy the required dlls alongside the executable file.

ChrisW67
9th September 2011, 03:16
Your program, compiled with a PRO file like:


TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

CONFIG -= qt

# Input
SOURCES += main.cpp

Has no dependencies on any part of Qt. I does have dependencies on system and possibly compiler libraries (MinGW and gcc). Since you don't share the error messages we cannot be specific.

seux
9th September 2011, 12:42
There are no error messages, the code compiles fine. I added a cin so that the console does not close immediatly:

#include <iostream>

using namespace std;

int main(void)
{
int var = 0;
cout << "Hello world" << endl;
cin >> var;
return 0;
}

when I add mingwm10.dll and libgcc_s_dw2-1.dll the programm gets executed, but nothing happens. No console pops up :(

My project file looks now like the one from Chris. I don't really know what other informations you need.

bah
9th September 2011, 14:31
Try to see the output on a command prompt/console run.

ChrisW67
10th September 2011, 08:03
No console pops up
Like all "Hello World" C programs it must be run from a command prompt.

No console pops up because your code does not include a WinMain entry point, code to create a Windows console, connect the stdin and stdout streams, and make it act as expected. If you use the Qt core then you can have this done for you (CONFIG += console). Since you do not want Qt dependencies you must do it for yourself. Have a look at http://dslweb.nwnexus.com/~ast/dload/guicon.htm (you might have to adjust for MingW).