Results 1 to 12 of 12

Thread: [Qt Console Application] QtCore module problems [SOLVED]

  1. #1
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default [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?
    Last edited by Azdingo; 2nd June 2010 at 19:03.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Console Application] QtCore module problems

    Post the compile errors you get.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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)

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt Console Application] QtCore module problems

    try to include file separately like this:
    Qt Code:
    1. #include <QStringList>
    2. #include <QString>
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt Console Application] QtCore module problems

    Just add this line
    Qt Code:
    1. #include <QStringList>
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 ?

  7. #7
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt Console Application] QtCore module problems

    Quote Originally Posted by Azdingo View Post
    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:
    Qt Code:
    1. #include <QtCore>
    To copy to clipboard, switch view to plain text mode 
    it works,
    but you included only QCoreApplication from QtCore/

  8. #8
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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..

  9. #9
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt Console Application] QtCore module problems

    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)
    Last edited by Zlatomir; 2nd June 2010 at 18:33.

  10. The following user says thank you to Zlatomir for this useful post:

    Azdingo (2nd June 2010)

  11. #10
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  12. #11
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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.

  13. The following user says thank you to Zlatomir for this useful post:

    Azdingo (2nd June 2010)

  14. #12
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt Console Application] QtCore module problems

    Alright, thanks again for your patience and your time

Similar Threads

  1. Console application beginning
    By Raccoon29 in forum Newbie
    Replies: 6
    Last Post: 23rd March 2012, 23:42
  2. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  3. Qt 4.5- cannot compile lphonon ( media module) application
    By varunmagical in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2009, 15:17
  4. Console application suspense
    By TheGrimace in forum Newbie
    Replies: 6
    Last Post: 1st October 2007, 14:52
  5. Module to process application parameters
    By Opilki_Inside in forum General Programming
    Replies: 4
    Last Post: 8th February 2007, 23:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.