Morpheus
Morpheus

Reputation: 1750

why I can't use normal C++ classes with Qt

Can anyone pls tell me that, why I can't use normal C++ classes within a Qt programme. If there is any class which aren't inherited from QObject the compiler give me a linking error called,

error LNK2019: unresolved external symbol _main referenced in function _WinMain@16

I'm using Qt 4.5.2 (compiled by myself) with vs2005. Pls help me to solve this !

Edit:

Example...

//UnitManager.h

class UnitManager
{
public:
//-Some code
};

//CivilizationViewer.h

class CivilizationViewer : public QMainWindow
{
Q_OBJECT
//-some code
};

//main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    CivilizationViewer w;
    w.show();
    return a.exec();
}

If I include UnitManager.h in CivilizationViewer.h compiler will give me that error. (eventhough I include UnitManager.h in main.cpp compiler will give me the error)

Upvotes: 0

Views: 3840

Answers (5)

Morpheus
Morpheus

Reputation: 1750

Thanks for everyone. I found the error. There is SDL.h in the UnitManager.h, so I have to add SDL.lib and SDLmain.lib (it is correct, right ?) then there is another definition for main in SDLmain.lib. So, there was a coflict between definitions of main. Therefore I added SDLmain.lib before adding qtmaind.lib. Then the problem solved by only giving a warning called,

warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

What is that warning ? I can just ignore the warning, but I like to get to know it ! Thanks

Upvotes: 1

David Menard
David Menard

Reputation: 2321

I think you actually made a win32 app. try replacing your main for:

int _tmain(int argc, _TCHAR* argv[]){
  your code
}

Seeing your error msg, i wouldn't guess Qt was your problem. Did you install the Visual Studio Qt integration? Try it and make a new Qt project.

Upvotes: 0

cyberconte
cyberconte

Reputation: 2398

It looks like you're not including the QT libraries properly... (the actual .lib file)

Upvotes: 0

MP
MP

Reputation:

It seems like you need to link with qtmain.lib (qtmaind.lib for debug builds). That library provides a WinMain function which is needed if you declared /subsystem:windows.

Source: http://lists.trolltech.com/qt-interest/2005-12/thread00170-0.html

Upvotes: 0

Evan Shaw
Evan Shaw

Reputation: 24547

The error you gave doesn't have anything to do with what classes you're using. It looks like it's related to the entry point you have set for your application. Usually you want to use main() instead of WinMain() in Qt programs. Make sure your configuration is set up right.

You included a little bit of code in your question. Is that everything? If so, you're missing a main function.

Upvotes: 8

Related Questions