Embed QT code into Visual Studio Project
-
Information: I have the QT SDK installed, as well as the Visual Studio 2010 add-on.
I have a project done in C++ using Visual Studio and I would like to add just a little QT code to it. Namely:
@bool ok;
QString text = QInputDialog::getText(
"Prompt", "Enter something:", QLineEdit::Normal,
QString::null, &ok, this );
if ( ok && !text.isEmpty() ) {
// user entered something and pressed OK
} else {
// user entered nothing or pressed Cancel
}@which would simply prompt the user for something.
What would be the simplest way (if there is one) to be able to include this code in my project? Library paths, copy over some files from the QT SDK, etc.?
-
Please note that for QInputDialog the QApplication object is required.
For me the simplest approach is to create *.pro file (probably using qmake -project mode) and after that generate vcproj file (qmake -t vcapp). But for the existing large MSVC-based project it may be a complex task.
Recommendation: create the test Qt project that calls QInputDialog. Open the generated with qmake test.vcproj and add to your project the following settings:
Compiler DEFINES
Compiler INCLUDE paths
Linker input libraries
-
The defines are normally: QT_LARGEFILE_SUPPORT, QT_THREAD_SUPPORT, QT_CORE_LIB, QT_GUI_LIB
for release additionally: QT_NO_DEBUGInclude paths are: $(QTDIR)\include
Libraries to use are normally: qtmain.lib, QtCore4.lib,m QtGui4.lib
additional libary paths are: $(QTDIR)\libBut you will have another problem:
Did you install Qt SDK for MSVS or with QtCreator for gcc?
If you used the one for gcc the library iunterfaces will not fit. C++ exports do not work cross compĆ¼iler from gcc to MSVC :-(