PDA

View Full Version : [Qt Console Application] QtCore module problems [SOLVED]



Azdingo
2nd June 2010, 16:01
Hi everyone,

I am using Qt 4.6 with visual studio 2008. My concern is, when I try to build a console application with qt(Using core and sql module), the code won't compile if I use some QtCore classes like QStringList. However, when I try a Qt Gui application, it works just fine. I can't figure this one out... anyone?

high_flyer
2nd June 2010, 16:02
Post the compile errors you get.

Azdingo
2nd June 2010, 16:11
#include <QtCore/QCoreApplication>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QStringList s;

return a.exec();
}

------ Build started: Project: DatabaseManager, Configuration: Debug Win32 ------
Compiling...
main.cpp
.\main.cpp(7) : error C2079: 's' uses undefined class 'QStringList'
--------------------

Generated pro file:
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------

# This is a reminder that you are using a generated .pro file.
# Remove it when you are finished editing this file.
message("You are running qmake on a generated .pro file. This may not work!")


TEMPLATE = app
TARGET = DatabaseManager
DESTDIR = ../Debug
QT += core sql qtmain
CONFIG += debug console
DEFINES += QT_LARGEFILE_SUPPORT QT_SQL_LIB
INCLUDEPATH += ./GeneratedFiles/Debug
DEPENDPATH += .
MOC_DIR += ./GeneratedFiles/debug
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(DatabaseManager.pri)

Zlatomir
2nd June 2010, 16:50
try to include file separately like this:


#include <QStringList>
#include <QString>

Lesiok
2nd June 2010, 16:51
Just add this line

#include <QStringList>

Azdingo
2nd June 2010, 17:36
Yeah, thanks but I was wondering why do I have to include these when I'm using console application and I don't have to include them when using the GUI. I mean, aren't these suppose to be already include when you use the Core module as state in http://doc.qt.nokia.com/4.6/qtcore.html#details ?

Zlatomir
2nd June 2010, 18:13
Yeah, thanks but I was wondering why do I have to include these when I'm using console application and I don't have to include them when using the GUI. I mean, aren't these suppose to be already include when you use the Core module as state in http://doc.qt.nokia.com/4.6/qtcore.html#details ?

Yeep, if you include like this:

#include <QtCore>
it works,
but you included only QCoreApplication from QtCore/

Azdingo
2nd June 2010, 18:15
Hmmm... Then, can you tell me why it works without including anything other than QtGui/QApplication when building a QtGui application? I can compile with QStringList without having to include anything else.. :confused:

Zlatomir
2nd June 2010, 18:29
Because they use QString internally in QApplication...
Quote from qapplication.h in Qt source files


static QStyle *setStyle(const QString&);

and they included the file indirectly from some other header files (and probably did the same thing with QStringList)

There is no reason for you to worry about, just include the header if it isn't already there ;)

LE: and on top of that they assumed that in GUI application you will want to use QStrings and list of QStrings, but in a console application you might not, you may be doing some server that needs std::string or some c complatible char* (or w equivalent)

Azdingo
2nd June 2010, 18:41
Alright, thank you!

The only thing that bug me from including QtCore, is that when I include the folder, my intellisense is gone because VisualStudio can't find it sources file even tough I have qt include folder sets in the file path.

Zlatomir
2nd June 2010, 18:52
Any way, it is not recommended to include the folder. (Except the demo projects or something similar)

Always include only the files needed (all the files needed and nothing but them ;) )
Even if seems more "comfortable" to just include one folder, don't do it, because compile time increase... file size increase... and i'm pretty sure that there are more reasons against that.

Azdingo
2nd June 2010, 18:55
Alright, thanks again for your patience and your time :)