Compiling a simple Qt “Hello World!” application within Visual Studio 2010 Express?

后端 未结 5 1227
予麋鹿
予麋鹿 2021-01-06 02:35

I\'m trying to build a basic Qt \"Hello, world!\" application inside Visual Studio.

I got the moc step to work (I think), but now I am at a loss as to h

相关标签:
5条回答
  • 2021-01-06 02:45

    Have you create the visual studio project using qmake first? The problem seems to be the moc compilation. Do you have qt plug-in installed and the qt path in enviromental variables? Can you add you hello world code so I can have a look at it?

    0 讨论(0)
  • 2021-01-06 02:58

    You need to add commands to generate QT metaclasses, then also include the generated files in your project as c++ code.

    Generating the QT metaclasses:

    • First, add your QT bin path into the Executable Directory. (This is in Configuration Properties > VC++ Directories)

    • Add your Header files that contain Q_OBJECT macros to the project.

    • Multi-select your header files, then right click on a header file, click Properties.

      • Change "Item Type" from "C/C++ Header" to "Custom Build Tool".
      • Set Command line to this: moc.exe "%(FullPath)" > "$(ProjectDir)MetaObjects\moc_%(Filename).cpp"
      • Set Description to this: QT: Generate $(ProjectDir)MetaObjects\moc_%(Filename).cpp (optional)
      • Set Outputs to this: $(ProjectDir)MetaObjects\moc_%(Filename).cpp
    • Run Build just to make it generate the metaobject code
    • Add the generated C++ files from the Project Directory Metaobjects folder into your project
    0 讨论(0)
  • 2021-01-06 02:59

    I was able to get QT to work with Visual C++ Express 2010 using http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/ and http://portfolio.delinkx.com/files/Qt.pdf as guides. Just in case anyone still is having problems.

    0 讨论(0)
  • 2021-01-06 03:03

    You cannot install the Qt VS plugin on the Express edition of VC++. Assuming you got the moc to compile, you also need to make sure you're including the appropriate libraries (*.lib files) at link time. This goes under Project properties > Linker > Input > Additional Dependencies.

    You will need qtcore4.lib at a minimum.

    Also make sure the Qt library path is in your library search path. On my computer it's c:\qt\4.6.2\lib.

    0 讨论(0)
  • 2021-01-06 03:08

    qmake will generate the moc voodoo from the header file in .pro file. As you aren't using qmake, by the sound of it, but a native visual studio project, this is probably the cause of the problem.

    If you use qmake to generate your visual studio project all your problems will go away and life will be sweet. Probably!

    I am using the open 2010.05; obviously you want to substitute the correct path for your version.

    set up the environment

    start 2010 command environment from the start menu
    -set include=%include%;C:\Qt\2010.05\qt\include
    -set lib=%lib%;C:\Qt\2010.05\qt\lib -set path=%path%;C:\Qt\2010.05\qt\bin
    -set QMAKESPEC=win32-msvc2010

    write code, create files etc

    generate the initial pro and makefile and fire up VS
    -qmake -tp vc
    -qmake

    you should now have a makefile - check that it works by running:
    -nmake

    now launch visual studio
    -VCExpress.exe /useenv
    -XXX.vcxproj can now be opened

    If this doesn't work you may need to build qt at against visual studio. This is very straightforward - go to the qt directory (from within the visual studio express command window) and type:

    configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
    
    0 讨论(0)
提交回复
热议问题