Console application beginning
Hi all,
newbie question after two years of honored Qt development :crying:
One sunny day I decided to kill myself trying to make up console applications...the beginning of the end.
I searched around for several hours, no examples, no a-b-c docs... I can't make a stupid hello world console application.
Code:
// main.cpp
#include <QtCore>
#include "backdoor.h"
int main(int argc, char *argv[])
{
Backdoor bd;
bd.spit("Hello world!");
return a.exec();
}
Code:
// backdoor.h
#include <QtCore>
{
private:
public:
Backdoor();
};
Code:
// backdoor.cpp
#include "backdoor.h"
Backdoor::Backdoor()
:out(stdout)
{
}
{
out << str;
}
this code looks trivial, a stupid output, but I've not been able to make it run properly (no output!)...
1_ what's wrong with QTextStream? What did I forget?
2_ what is the basis concept to make console application? (an example of usage with an object and, possibly, an event to initiate me would be very very very apprecciated)
120 Experience Points to who'll answer good! :p
Thanks in advance
Re: Console application beginning
Use
Code:
out << str << flush;
or
Code:
out << str << endl;
Re: Console application beginning
Quote:
Originally Posted by
Raccoon29
1_ what's wrong with QTextStream? What did I forget?
You forgot to tell it where the output should go. Initiate it with stdout or stderr and it will work.
Edit: Aa... I just noticed you did :) Maybe you forgot to activate console support when running on Windows? Also remember to flush the stream at some point.
Quote:
2_ what is the basis concept to make console application? (an example of usage with an object and, possibly, an event to initiate me would be very very very apprecciated
I don't really understand the question...
Re: Console application beginning
Are you compiling on Windows? By default on Windows there is no console output. Try add CONFIG += console to your project file.
Re: Console application beginning
First really thank you to all RSX, Bender86 and S.Wysota!
@RSX & S.Wysota
out << str << flush;
worked! I wasn't aware that stream required flush... my bad.
Quote:
Are you compiling on Windows? By default on Windows there is no console output. Try add CONFIG += console to your project file.
yes, I'm under Windows. I'm using QtCreator (THE amazing ultimate Qt IDE) and it provided that config for me when creating the new project.
@S.Wysota
Quote:
Edit: Aa... I just noticed you did
it happens in the best families too :p
Quote:
I don't really understand the question...
I bad explained. I thought that console application required some different structure than QApplication for example...but it was just a my wondering.
Another little question to close this thread (and complete the subject): what is "the most correct" way to close this application from Backdoor? I mean using QCoreApplication: some signal, some method...? (an example would be great)
Re: Console application beginning
Re: Console application beginning
I managed to create a simple console "hello world" with QT Creator
used creator 2.4.1 and QT 4.8.0 on windows 7
two ways to do this
Plain C++
do the following
File- new file project
under projects select : other Project
select "Plain C++ Project"
enter project name 5.Targets select Desktop 'tick it'
project managment just click next
you can use c++ commands as normal c++
or
QT Console
File- new file project
under projects select : other Project
select QT Console Application
Targets select Desktop 'tick it'
project managment just click next
add the following lines (all the C++ includes you need)
add "#include 'iostream' "
add "using namespace std; "
after QCoreApplication a(int argc, cghar *argv[]) 10 add variables, and your program code..
example: for QT console "hello world"
file - new file project 'project name '
other projects - QT Console Application
Targets select 'Desktop'
project management - next
code:
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout<<" hello world";
return a.exec();
}
ctrl -R to run
compilers used for above MSVC 2010 (QT SDK) , and minGW(QT SDK)
hope this helps someone
As I have just started to use QT recently and also searched the Www for info and examples to get started with simple examples still searching...