Welcome! Log In Create A New Profile

Advanced

Hello World

Posted by ShaunGVW 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Hello World
August 17, 2009 12:33PM
Soemone at work is wanting to learn C++, and is using Qt Creator to start. He is starting the Hello World program, but is getting no output at the console, i.e. it should display "Hello World", but it doesn't give any output at all. I'm at work, and so can't compare to my assignments what is wrong, so maybe someone can advise. These are his files...

[.pro]
CONFIG += qt console
SOURCES += main.cpp

[.c++]
#include <iostream>
using namespace std;

int main(int argc, char **argv[])
{
cout << "Hello World!" << endl;

return 0;
}


Thanks.
Anonymous User
Re: Hello World
August 17, 2009 12:37PM
#include <QtDebug> //or <QDebug>

//usage:
qDebug() << " hello world";
Re: Hello World
August 17, 2009 01:08PM
Thanks. But qDebug isn't part of standard c++
Also now it looks for QtCored4.dll to work.
Anonymous User
Re: Hello World
August 17, 2009 01:20PM
use std c++ for std c++ stuff. I don't think cout outputs to IDE console
Anonymous User
Re: Hello World
August 17, 2009 01:21PM
ShaunGVW Wrote:
-------------------------------------------------------
> Also now it looks for QtCored4.dll to work.

this might be your problem.
Re: Hello World
August 17, 2009 02:10PM
Why not go the VS Studio 2005 or 2008 Express route, if it is normal C++ he is wanting to learn?
Anonymous User
Re: Hello World
August 17, 2009 02:36PM
after he learns c++, he should work through the Ezust textbook. I reckon it's one of the best Qt books out there.

I found linux a friendly environment to learn qt in (ok, there will be some days when you struggle to re-use .so files (dll's), but that's been posted about and google can help there).
Another magic tool I found is a code profiler called valgrind http://en.wikipedia.org/wiki/Valgrind
you can run valgrind on your executable and get all sorts of information, like where all the memory leaks are and what's causing it. No debugger will give you that info? Or does VS do this?
Re: Hello World
August 17, 2009 02:47PM
@Rick - can you use valgrind on windows?
Anonymous User
Re: Hello World
August 17, 2009 02:49PM
i don't think so
Quote

As of version 3.4.0, Valgrind supports Linux on x86, x86-64 and PowerPC. Support for Mac OS X has been merged, and should appear in version 3.5.0.[6] There are unofficial ports to other UNIX-like platforms (like FreeBSD[7], and NetBSD[8]).

This is why I prefer the coding freedom of *nix. One day, when I'm big, I'll code on windows platforms (or maybe not..)
Re: Hello World
August 17, 2009 02:54PM
Maaaannnnn, windows sucks.
One day, when I'm big, I'll code on *nix platforms (or maybe not..) winking smiley
avatar Re: Hello World
August 17, 2009 06:34PM
I just created a new console app using the QCreator wizard and pasted your source into the project. It compiles file and runs with output from the console.

The default project file created is:

#-------------------------------------------------
#
# Project created by QtCreator 2009-08-17T18:23:18
#
#-------------------------------------------------

QT       -= gui

TARGET = Scratch
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

but I'm sure that you can eliminate all the Qt libraries with the following, which also compiles fine and runs with output. (remember to run qmake again)

TARGET = Scratch
CONFIG -= QT
CONFIG   += console

TEMPLATE = app


SOURCES += main.cpp
Re: Hello World
August 17, 2009 07:29PM
Thanks for rhe input. The following seems to be minimal code needed.

[.pro]
CONFIG += console

SOURCES += main.cpp

[.cpp]
#include <QtCore/QCoreApplication>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
return 0;
}
Anonymous User
Re: Hello World
August 17, 2009 08:46PM
why bother with cout? If he's going to learn c++ via Qt, then he may as well go with qDebug() *shrugs*
Re: Hello World
August 18, 2009 06:54AM
Because he is only just starting out, and is going through an introductory book, and it is always nice to get the samples working. He wouldn't always have someone around to give him the alternative for Qt. Qt Creator is an IDE for doing Qt in, but you can do standard c/c++ in it. It is a nice IDE to use.
avatar Re: Hello World
August 18, 2009 08:46AM
qDebug() is not meant to be used as the primary output for programs. It sends output to stderr and not stdout. Also if you compile your program in release mode (CONFIG += release), it's functionality will be removed. Rather use the STL cout or make the similar version using QTextStream and stdout.
Anonymous User
Re: Hello World
August 18, 2009 09:46AM
An invaluable book for C++, imo, is C++ The Complete Reference, 3rd Ed (H.Schildt)(1998) - McGraw-Hill
It's great for beginners.
Sorry, only registered users may post in this forum.

Click here to login