cannot run simple Qt example program, vague error - qt

I'm trying to run a simple example program Qt dialog example.
I compiled it using cmake and nmake, but upon running I get:
Cannot correctly start the application (0xc0150002). Click OK to close the application.
The main.cpp I'm using:
#include <QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog dialog;
return dialog.exec();
}
The simplest thing I can get to work is
#include <QApplication>
#include <iostream>
#include "dialog.h"
using namespace std;
int main(int argc, char *argv[])
{
cout << "test!" << endl;
// QApplication app(argc, argv);
// Dialog dialog;
//return dialog.exec();
return 0;
}
So I can't use anything Qt related, any ideas on how to solve this issue?
Thanks!

It might be that your Qt dlls aren't found when the program starts.
You can check this by copying Qt dll files from Qt's Bin folder to the folder where your program executable is.
Or set the PATH system variable to contain the folder where the Qt libraries are, dlls under windows.
If you are under windows, then there is a tool you can use.
Depedency Walker, to start it, start the "visual studio command prompt" and type "depends"
Drag & Drop your application file to the dependency walker and you should see what dlls it cannot load.
Note that the program isn't always accurate though, but in your case it should work.

I used the tool and found that a few dll's seem to be missing. These being MSVCP90D.DLL, MSVCR90D.DLL, GPSVC.DLL, IESHIMS.DLL.
After some googling it seemed that the problem could be using VS2010 with precompiled Qt binaries for VS 2008. Now I recompiled Qt with VS 2010 but the problem remains the same.
But when recompiling I also compiled the examples, including the one I was trying to get to run. Seems the compiled example of Qt runs perfectly, but my own compiled version keeps giving the same error and the dll's are still missing..
How is this possible, I'm compiling with the same Qt include/binary dir?
The information asked:
the CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
PROJECT(test)
FIND_PACKAGE(Qt4)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
LINK_LIBRARIES( ${QT_LIBRARIES} )
set(all_SOURCES main.cpp)
QT4_AUTOMOC(${all_SOURCES})
add_executable(Test ${all_SOURCES})
target_link_libraries(Test
${LINK_LIBRARIES})
I'm using Visual Studio 2010 on Windows 7. I'm using the VS2010 command prompt to build and run the executable.
Thanks!

Related

Successfully execute a QT application build with codeblocks on windows

For some reason, I am forced to create a distribution of my application (originally developed on windows with visual studio) running on a Linux server. But even the smallest step towards Linux is full of pain because nothing seems to work anymore. I'm currently trying to transfer my project to the IDE codeblocks on Windows because I want to build the project with GCC first. If I succeed, I am probably able to copy and paste the project on a Linux machine and simply rebuild it.
Unfortunately, I am not able to run a Qt HelloWorld project build with MinGW and Codeblocks. I followed these instructions setting up the project:
http://forums.codeblocks.org/index.php?topic=23059.0
and besides:
http://www.kerrywong.com/2008/07/12/codeblocks-settings-for-qt-development/
There is no problem during the build. However, if I try to execute the application, I immediately get a runtime error "Cannot start the application (0xc0000...7b)"
So I also tried to deploy Qt for windows applications without any effect. What am I missing?
cmd: "C:\Qt\5.11.2\mingw53_32\bin\windeployqt.exe" "C:\Users\Steph\ownCloud\Codeblocks\cb_fail\bin\Debug\cb_fail.exe"
code:
#include <QString>
#include <iostream>
int main(int argc, char* argv[])
{
QString smth = "Hello Qt";
std::cout << smth.toStdString();
}
Codeblocks compiler settings

CMake built Qt5 QMediaPlayer program fails only when installed

I have a simple Qt 5.4 application that uses QMediaPlayer. I build it using CMake. The executable created from running "make" works correctly and plays the song. The executable created and installed from running "make install" gives the following error on Ubuntu 14.04
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
My code:
#include <QMediaPlayer>
#include <QApplication>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMediaPlayer myAudio;
myAudio.setMedia(QUrl::fromLocalFile("/absolute/path/song.mp3"));
myAudio.setVolume(50);
myAudio.play();
return app.exec();
}
My CmakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
project(QtTestingExe)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Multimedia REQUIRED)
add_executable(QtTesting QtTesting.cpp)
target_link_libraries(QtTesting Qt5::Widgets Qt5::Multimedia)
install(TARGETS QtTesting DESTINATION bin)
This is most probably related to the CMake RPATH handling. Quoting from Cmake docs:
"CMake will link the executables and shared libraries with full RPATH to all used libraries in the build tree. When installing, it will clear the RPATH of these targets so they are installed with an empty RPATH"
This may explain the behavior you're observing.
If this is indeed the case, adding the QT path to the LD_LIBRARY_PATH environment variable will probably be enough.
Alternatively the CMAKE_INSTALL_RPATH could be set to the correct path inside the CMakeLists.txt.
There are more options to play with RPATH settings in CMakeLists.txt - see the documentation link above.

Qt and LNK1104 cannot open file

I am trying to accomplish the "hello world" tutorial with Qt 5.0.2 for Windows 64-bit (VS 2012, 500 MB) (Info).
However when I press Run the project I have an LNK1104: cannot open file 'debug/Hello.exe' error. However I see that this file is created under project folder "F:\QT\Hello\build-Hello-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug". Thank you in advance
Main.cpp
#include <QApplication>
#include <QPushButton>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
QPushButton button;
button.setText("Hello world !");
button.setToolTip("heheheheheheheh");
button.show();
return app.exec();
}
Hello.pro
TEMPLATE = app
TARGET = Hello
QT = core gui
QT += widgets
SOURCES += \
main.cpp
Most likely cause for the problem: .exe file of your program is still running. Check with Task Manager.End this process from task manager and again try to built it.It will definitely run.
I had the same issue to fix it I went to project right above the run (play button)
clicked on build and switched to debug. Not sure why but it worked for me.
Hope that helped
It might be caused by file permission or linking issues.
Additionally, Microsoft Development Network has an extensive list of possible causes (and solutions) for your problem:
http://msdn.microsoft.com/en-us/library/ts7eyw4s%28v=vs.110%29.aspx

Problem with code::blocks;Qt4;MingW;The procedure entry point.. could not be located in the dynamic link library QtCore.dll:

I am running Code::Blocks 10.05 with the MingW compiler package on a Win7-32 box.
I downloaded and installed the Qt libs for Windows/MingW (qt-win-opensource-4.7.3-mingw.exe) - installation went smoothly - BUT when it prompted me for the directory for MingW and I pointed it to Code::Blocks installation directory, Qt installer told me my Qt package was for MingW 4.4 and I had 4.4.1 installed - 'installation may not work'. I installed anyhow, figuring there's no significant difference between 4.4 and 4.4.1 and the installation finished without error, all the Qt libs and tools are installed.
Afterwards, in Code::Blocks I created a small test project using the Code::Blocks wizard - here is the code:
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
return app.exec();
}
The code built fine in the IDE - no errors or warnings, but when I ran it, I immediately received this error message, and the app exited with an error code:
"The procedure entry point _ZI3qFlagLocationPKc could not be located
in the dynamic link library QtCore.dll"
Anybody know what's going on here? Is it because of the MingW version discrepancy I was warned on, or some other reason? How can I fix this? I want to use Qt Code::blocks, not Nokia QtCreator.
TIA
Add %qtDir%\lib to your path before trying to copy all to system32. Reboot after adding, then all should run fine.
Also, you may need to rebuild qt libs with your compiler if all is still not working...
I used to have that errors, too. And having Qt libs in PATH doesn't seem to help, someone told me to put them into %WINDIR%\system32 and everything works fine after that...
You should create the variables:
QTDIR - C:\Qt\4.7.3 (it's mine, you should write yours)
QMAKESPEC - win32-g++ (for MinGW)
PATH - C:\Qt\4.7.3\bin;C:\mingw\bin

How to link Qt to and already existing MinGW installation?

When installing Qt, I unchecked the MinGW installation option as I have it already installed. Now after installing I am not able to build an example program I found in a book. All the build options in the menu are disabled. the code I am trying to execute is:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
When I keep the mouse pointer above the QApplication or QLabel header - the yellow pop up says "No Such File or Directory". I am using the Qt Editor.
As far as I can see your problem is in the include headers which are not visible in your build environment. You should check somewhere in the QT editor settings where to set the path to the QT library include headers.
Try the menu Help/Start Updater. In the dialog choose "Package manager", then click Next. A new dialog will open with a selection of components. Check:
"Qt SDK/Development tools/Desktop QT/Qt x.x.x (Desktop)/Desktop Qt
x.x.x MinGw.
Then click Next and let it update. This will enable MinGW in Qt. Then you might have to check that the toolchain is available, by clicking on the menu:
Tool / options / Biuld & Run
Finally, if you started your project already using a different tool chain, you might want to change it to MinGW. So in the main window of Qt Creator choose the "Projects" tab on the left and select the MinGW tool chain.
Hope that helps

Resources