Results 1 to 7 of 7

Thread: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded projects

  1. #1
    Join Date
    Jul 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Compiling QT programs in Visual C++ 2008 by including batch files, reloaded projects

    Hi, Meek here

    I use Visual C++ 2008 express to practice writing QT4.5 based code in Windows XP

    I include batch files to do my QMake handling for me, and the .bat file typically looks like this
    "c:\Program Files(x86)\Microsoft Visual Studio 9.0\vc\bin\vcvars32.bat
    c:\qt4_5\qt\bin\qmake -project -t vcapp "CONFIG+=console" -o Foundations_Of_QT_chap1_QT_Inherited.pro
    c:\qt4_5\qt\bin\qmake
    "
    (I am trying out the example from Joseph Thelin's book "Foundations of Qt Development", example from page 9)
    I run the batch file from the command prompt

    Visual C++ then reloads the Visual C+ project.

    I have 2 questions about this
    1) Is there a way to make Visual C++ 2008 Express run my batch file from within, so I do not have to go jumping around to the command prompt?

    2) Is there some way of preserving the included file filters in my project file so that the Visual C++ project file will still keep my filters in place which show my batch files?, or my other filter that I use for keeping project notes.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    Instead of doing all of the above, why not just download the Visual Studio Qt plugin? No messing around with the command line then, it's all integrated - so you would just use the standard VS "Build" option which is typically F7. This means you keep all your filters etc.

  3. #3
    Join Date
    Jul 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    I appreciate the advice, but I only have the express edition, and from what I have been reading (and my attempt to install the plugin for VS), the plugin does not work with Visual studio, so I use the batch files instead

    I'm currently having a devil of a time getting Visual Studio to handle QT compiling without active rebellion (linker errors)

    current problem that I am having is that the code I compile always gets screaming linker errors with QT

    For instance, I'm trying to compile the code on pages 14-16 of "Foundations Of QT Development", by Joseph Thelin, and I am trying to use the following batch file to generate the correct project

    BatchFile "QTBatch.bat"
    "
    c:\Program Files(x86)\Microsoft Visual Studio 9.0\vc\bin\vcvars32.bat
    c:\qt4_5\qt\bin\qmake -project -t vcapp "CONFIG+=console" -o Foundations_of_QT_P14_signalslot.dsp Foundations_of_QT_P14_signalslot.pro
    c:\qt4_5\qt\bin\qmake
    "

    I got previous programs to compile before when I was not using Signal and slots, now when I run my batch file and try to run the new project that has been generated, I get the following errors

    "1>Compiling...
    1>moc_MyClass.cpp
    1>main.cpp
    1>.\main.cpp(3) : warning C4100: 'argv' : unreferenced formal parameter
    1>.\main.cpp(3) : warning C4100: 'argc' : unreferenced formal parameter
    1>Generating Code...
    1>Linking...
    1>moc_MyClass.obj : error LNK2005: "public: __thiscall MyClass::MyClass(class QString const &,class QObject *)" (??0MyClass@@QAE@ABVQString@@PAVQObject@@@Z) already defined in main.obj
    1>moc_MyClass.obj : error LNK2005: "public: class QString const & __thiscall MyClass::text(void)const " (?text@MyClass@@QBEABVQString@@XZ) already defined in main.obj
    1>moc_MyClass.obj : error LNK2005: "public: int __thiscall MyClass::getLengthOfText(void)const " (?getLengthOfText@MyClass@@QBEHXZ) already defined in main.obj
    1>moc_MyClass.obj : error LNK2005: "public: void __thiscall MyClass::setText(class QString const &)" (?setText@MyClass@@QAEXABVQString@@@Z) already defined in main.obj
    1>debug\Foundations_of_QT_P14_signalslot.exe : fatal error LNK1169: one or more multiply defined symbols found
    1>Build log was saved at "file://c:\Users\meek\Documents\Visual Studio 2008\Projects\Foundations_of_QT_P14_signalslot\Fou ndations_of_QT_P14_signalslot\debug\BuildLog.htm"
    1>Foundations_of_QT_P14_signalslot - 5 error(s), 2 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    "

    How do I fix this?

  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: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    In this case (VS express) i suggest you use the Qt Creator (from Qt Windows SDK - witch goes out of the box) this is better than try to "convince" VS express to run the batch files.

    Unless you have a good reason for using VS C++ compiler and not mingW (gcc port).

  5. #5
    Join Date
    Jul 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    My main reasons are
    1) I do not want to run MinGW
    2)QMake has the option of creating Visual C++ project files that allow people to compile with them.

    QT seems like too nice a tool for me to not be able to figure out how it works and get stumped on configuration issues instead of coding errors.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    In that case remember that "qmake -project" will overwrite your Visual Studio project, so only run it if you have to rather than every time.
    Second, ensure to run MOC on any header files that use Q_OBJECT and include these files in your compilations and linker. Don't #include them in other code.

    (It may also be easier to get Qt Creator to run the command line Visual C compiler)

  7. #7
    Join Date
    Jul 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Compiling QT programs in Visual C++ 2008 by including batch files, reloaded proje

    Sorry about all of this, I solved my compiler problem.

    The batch file method works well enough, but it seems to have problems compiling in Visual C++ 2008 express if the declaration of a class and the implementation of the functions of that class are both in the same header file.

    For example, if "MyClass" has both the class declaration in "MyClass.h"
    and the class function implementations in "MyClass.h"
    with the main function implemented in a .cpp file such as "main.cpp",

    then if we use the batch file with the commands
    "c:\Program Files(x86)\Microsoft Visual Studio 9.0\vc\bin\vcvars32.bat
    c:\qt4_5\qt\bin\qmake -project -t vcapp -r "CONFIG+=console" -o Foundations_of_QT_P14_signalslot.pro
    c:\qt4_5\qt\bin\qmake
    "

    and we open the generated ".VCProj" in Visual C++ and compile the project, we will get linkage errors.

    ----
    If we declare the Class declaration in a header file (ex: "MyClass.h")
    and write the class function implementations in a .cpp file (ex:MyClass.cpp")
    and the main function in another .cpp file,

    If we run the same batch file, open the generated ".vcproj" in Visual C++ and compile the project, we will get our compiled application (.exe) (barring coding errors)

    Thank you to everyone that responded.
    "

Similar Threads

  1. Replies: 8
    Last Post: 28th October 2013, 01:08
  2. Demo projects not compiling
    By vaibhavsri in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 04:23
  3. Options for compiling 64 bit programs with Qt?
    By Skywalker in forum Qt Programming
    Replies: 0
    Last Post: 9th July 2009, 04:49
  4. Replies: 7
    Last Post: 2nd July 2009, 17:35
  5. Can't compile programs in Visual Studio.net 2005
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2006, 14:10

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.