Embed QT code into Visual Studio Project
-
wrote on 21 Nov 2010, 22:20 last edited by
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.?
-
wrote on 22 Nov 2010, 05:59 last edited by
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
-
wrote on 23 Nov 2010, 08:06 last edited by
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 :-(
-
wrote on 23 Nov 2010, 08:09 last edited by
[quote author="giesbert" date="1290499607"]Did you install Qt SDK for MSVS or with QtCreator for gcc?[/quote]
Sure, Qt should be compiled with MSCV compiler. Even better, compile it from sources to use exactly the same MSVC runtime libraries.
4/4