sys info : win xp SP3 , Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5 SP1
Qt Add-in 1.1.5
I installed Qt 4.6.3 from the site http://qt.nokia.com/downloads/windows-cpp-vs2008.
Then I added the Add-in Qt 1.1.5 and configured the PATH variable.
When I open a new QT project , default example works just fine.
On Nokia (qt) site I found some examples but it seems that things are not working properly.
Here is one of many examples that do not work :
#include <QtGui>
#include <QWidget>
class QLabel;
class QLineEdit;
class QTextEdit;
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
{
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;
QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameLine, 0, 1);
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
mainLayout->addWidget(addressText, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Simple Address Book"));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AddressBook addressBook;
addressBook.show();
return app.exec();
}
Compiler says this ::
Output Window
Linking...
main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall AddressBook::metaObject(void)const " (?metaObject#AddressBook##UBEPBUQMetaObject##XZ)
main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall AddressBook::qt_metacast(char const *)" (?qt_metacast#AddressBook##UAEPAXPBD#Z)
main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall AddressBook::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#AddressBook##UAEHW4Call#QMetaObject##HPAPAX#Z)
main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const AddressBook::staticMetaObject" (?staticMetaObject#AddressBook##2UQMetaObject##B)
C:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\Debug\vs_03.exe : fatal error LNK1120: 4 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\vs_03\Debug\BuildLog.htm"
vs_03 - 5 error(s), 0 warning(s)
It seems to me that the thing has to do with the use of macro Q_OBJECT but just dont know what to do that thing starts to work properly.
Maybe wrong installation or ... NO IDEA
Any help is appreciated.
I don't think it's a wrong installation - I assume you're using Visual Studio to build the project and in that case, you also need to tell it to build the _moc.cpp files that should have been generated for your class AddressBook.
If they haven't been generated you also need to run moc on the header files for AddressBook.
Any time you need moc to run against your files and you don't have your class in a separate header and implementation file you need to have a #include "FILENAME.moc" at the end of your file. If you were to add that after your main function, everything should work.
You should be able to test this by going into your project directory and doing the following:
Delete any makefiles that may be present
Run the Visual Studio Command Prompt
Run qmake -project to generate a project file
Run qmake to generate the makefiles
Run nmake to build the project
The nmake command should completely successfully and without linking errors on a simple project like the above. For more complex projects, you might need to modify the .pro file to include Qt`s webkit or otherwise make accessible options which are not available by default.
The alternative is to move the class definition for AddressBook into a header file with an appropriate implementation (cpp/cxx) file.
I find solution.
Read all the details about the installation on this page >>
http://dcsoft.wordpress.com/?aspxerrorpath=/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx.
After a whole day of studying and configuration, I finally managed to enable QT 4.6.3. on the VS 2008. Follow the detailed instructions and there should not be a problem.
My problem was that I used the following options:
Starting with Qt 4.6, the LPGL version now comes pre-built for Visual Studio 2008 RTM. If this fits your need, you can simply install it and skip to INSTALL VISUAL STUDIO ADD-IN.
This was wrong in my case so I go to next chapter :
DOWNLOAD QT SOURCE CODE
As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions: ................................................................................................................................................................................................................................. etc. READ ON THE SITE.
For now all works great.There are no errors in linking. MOC works fine ...
Related
I am using VS 2019 for developing QT using the QT extension, however, when I add a class to the project that inherits from QObject and added Q_OBJECT, I am getting linker errors such as :
Error LNK2001 unresolved external symbol "public: virtual void * __cdecl MyThread::qt_metacast(char const *)" (?
It does seem like the new class is not build or compiled properly, something related to MOC,
How to resolve this and include the file I just added to be MOCe build?
I am trying to compile this simple qt application with Visual Studio express 2013 for Desktop:
#include <QApplication.h>
#include <QTextEdit.h>
int main(int argv, char **args)
{
QApplication app(argv, args);
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
but when I compile I have this error :
Errore 1 error LNK2019: riferimento al simbolo esterno
"__declspec(dllimport) public: __thiscall
QApplication::QApplication(int &,char * *,int)"
(__imp_??0QApplication##QAE#AAHPAPADH#Z) non risolto nella funzione
_main C:\Users\Enrico\Documents\Visual Studio 2013\Projects\Progetto2\Progetto2\Origine.obj Progetto2
English:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall
QApplication::QApplication(int &,char * *,int)"
(__imp_??0QApplication##QAE#AAHPAPADH#Z) referenced in function
_main C:\Users\Enrico\Documents\Visual Studio 2013\Projects\Progetto2\Progetto2\Origine.obj Progetto2
Thanks for everyone who helps me.
The root cause is the Qt libraries like QtCore5.dll are not being linked. You can manually specify them by editing the Linker options to your project, but but the elegant way is to use the Qt Visual Studio Add-in to easily do a number of things such as create new Qt projects with the Qt libraries selected. This will resolve your link error. The add-in also adds debugger visualization for Qt types, ties in Qt Designer, and many other useful things for using Qt for within Visual Studio.
But add-ins are not supported in Visual Studio Express. Instead you must install Visual Studio 2013 Community. VS 2015 Community is now shipping also, but the Qt add-in hasn't been updated to work with it yet.
I am trying to compile a minimal Qt Console application with event loop and a custom class with inline definition of its constructor like https://stackoverflow.com/a/4182144/1619432 and get three cryptic linker errors (using Qt 4.8.1 and MSVC 2010 Express C++):
main.obj:-1: error: LNK2001: Unresolved external symbol ""public: virtual struct QMetaObject const * __thiscall ....
with ::metaObject, ::qt_metacast, ::qt_metacall.
#include "main.moc"
just above the int main(...) is critical. If the file is not found, try cleaning the project / deleting the build directories, running qmake, restarting Qt Creator or even the whole system.
This may have to do with paths in environment variables (maybe set previously by a different project).
Another common reason seems to be a forgotten Q_OBJECT macro in the class declaration, or as above, run qmake after including it.
Good luck!
I'm trying to compile a project in Visual Studio 2010, with Qt 4.8.4.
When I build it, I obtain linker errors like following ones:
error LNK2001: external symbol "__declspec(dllimport) public: class QByteArray & __thiscall QByteArray::operator=(class QByteArray &&)" (__imp_??4QByteArray##QAEAAV0#$$QAV0##Z) not resolved
error LNK2001: external symbol "__declspec(dllimport) public: class QString & __thiscall QSTring::operator=(class QString &&)" (__imp_??QString##QAEAAV0#$$QAV0##Z) not resolved
You can see the move constructor in linker, but I'm not using any C++11 feature.
The linker error appears in files where I've code like this:
QByteArray xTmpArray;
QString xString;
...
xTmpArray = xString.toAscii();
If I comment the assignment line, the link error disappears (same for QString assignment).
How can I eliminate these link errors?
I've solved. It was (naturally) a linking problem, because they gave me libraries compiled with Visual Studio 2008, that does not support move constructor. I've used the correct version, compiled with VS2010, and all works ok.
I wrote this code:
#include <QString>
#include <QByteArray>
int main() {
QString s("a");
QByteArray ba = s.toAscii();
return 0;
}
I am compiling it with command:
g++ -I /usr/include/qt4/QtCore/ -I/usr/include/qt4/ qtuse.cpp -lQtCore -o qtuse
And I have no problem. Looks like you have forgotten to link your program with QtCore.
Check your project settings. You should add Qt's lib dir to link paths.
In Microsoft Visual Studio 2015 go to:
(Project properties)->General->Platform Toolset
and set that to visual studio 2013 (v120)
This have worked for me :)
This error happens when there is version mismatch between MSVC and pre-built Qt binaries. Don't do that.
If you're using MSVC2015 you need to link against the pre-build MSVC2015 Qt libraries.
I am trying to make a very simple GUI application, on the top of some C++ code which I wrote. My problem could be simplifed to the following:
#include <QtGui\QDialog>
void setup(int argc, char **argv) {
QDialog dlg;
}
int main(int argc, char **argv) {
setup(argc, argv);
}
I configured my Qt library, and I am pretty sure that the libraries are compatible with my Visual Studio 2010 (other projects worked fine), but I don't know if I should create a header file. I am always receiving these errors:
>main.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall QDialog::~QDialog(void)" (??1QDialog##UAE#XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall QDialog::QDialog(class QWid.................
The errors you got signals that VS compiler cannot determine addresses of invocation the external functions you've used, namely ctor and dtor for QDialog class object. To avoid such errors you should specify the location of the libraries containing the definitions of that functions. In order to achieve this you should use "Project Properties"->"Configuration Properties"->"Linker"->"Input", then in the "Additional Dependencies" line input the absolute path to the external libs (e.g. "C:\Qt\4.8.3\lib\QtGui.lib").I suppose if you only got that errors you mentioned you set your include paths correctly. So specifying input libraries should help.For the future I'd suggest you install Qt VS Add-in. It adds some options to an ordinary VS "Create new project" dialog, so you can choose "New Qt project" and all the required paths will be set automatically.