Qt5 in VS2012 Getting Started code gives me undefined class errors



  • I built Qt5 and added the .lib files and header files from qtbase/include and qtbase/lib into my project in VS2012 Update 1. I'm not using the Qt plugin for now, but that shouldn't matter.

    The code I'm using is this:
    @#include <QtGui>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QWidget window;
    window.resize(320, 240);
    window.show();
    window.setWindowTitle(
    QApplication::translate("toplevel", "Top-level widget"));
    return app.exec();
    }@
    QtGui is included fine. All the classes show up w/ intellisense.

    @The errors I get, however, look like this:
    1>------ Build started: Project: QtTest, Configuration: Debug Win32 ------
    1> Main.cpp
    1>c:\users\kyle\documents\visual studio 2012\projects\qttest\qttest\main.cpp(5): error C2079: 'app' uses undefined class 'QApplication'
    1>c:\users\kyle\documents\visual studio 2012\projects\qttest\qttest\main.cpp(5): error C2078: too many initializers
    1>c:\users\kyle\documents\visual studio 2012\projects\qttest\qttest\main.cpp(5): error C2440: 'initializing' : cannot convert from 'char *[]' to 'int'
    1> There is no context in which this conversion is possible
    1>c:\users\kyle\documents\visual studio 2012\projects\qttest\qttest\main.cpp(6): error C2079: 'window' uses undefined class 'QWidget'
    ... more@

    Any ideas?


  • Moderators

    -Have you added `#include <QApplication>'?-

    Edit: Sorry, didn't read properly... my bad. No ideas, sorry



  • Same Problem here :-(



  • Yeah, still looking for a solution :|



  • Same problem with VS2010 :/ AND NO ANSWERS



  • This makes sense, QApplication isn't in QtGui.

    [quote author="JKSH" date="1356500304"]-Have you added `#include <QApplication>'?-

    Edit: Sorry, didn't read properly... my bad. No ideas, sorry[/quote]



  • I got lucky.

    This helped me:
    @#include <QtWidgets/QApplication>@

    In .pro file added these:
    @QT += core gui widgets@

    This still did not worked, so next was to delete everything else except my main.cpp and *.pro file as well as deleting previously compiled output directory. After deleting everything my next build worked :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.