[Qt Console Application] QtCore module problems [SOLVED]
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?
Re: [Qt Console Application] QtCore module problems
Post the compile errors you get.
Re: [Qt Console Application] QtCore module problems
#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)
Re: [Qt Console Application] QtCore module problems
try to include file separately like this:
Code:
#include <QStringList>
#include <QString>
Re: [Qt Console Application] QtCore module problems
Just add this line
Code:
#include <QStringList>
Re: [Qt Console Application] QtCore module problems
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 ?
Re: [Qt Console Application] QtCore module problems
Quote:
Originally Posted by
Azdingo
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:
it works,
but you included only QCoreApplication from QtCore/
Re: [Qt Console Application] QtCore module problems
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:
Re: [Qt Console Application] QtCore module problems
Because they use QString internally in QApplication...
Quote from qapplication.h in Qt source files
Quote:
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)
Re: [Qt Console Application] QtCore module problems
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.
Re: [Qt Console Application] QtCore module problems
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.
Re: [Qt Console Application] QtCore module problems
Alright, thanks again for your patience and your time :)