Testing a simple qt console program on non-qt-installed pc - qt

The code is very simple:
#include <QApplication>
#include <QDebug>
int main(int argc,char* argv[])
{
QApplication a(argc,argv);
qDebug()<<"Hello world!";
return a.exec();
}
And the .pro file's content is:
CONFIG+=qt debug console
SOURCES+=a.cpp
TARGET=trytoshow
I used the dumpbin utility to find out on which .dll the console program depends:
C:\Program Files\Microsoft Visual Studio 9.0\VC>dumpbin -dependents "G:\Public\H
ello world\trytoshow.exe"
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file G:\Public\Hello world\trytoshow.exe
File Type: EXECUTABLE IMAGE
Image has the following dependencies:
QtGuid4.dll
QtCored4.dll
MSVCR90D.dll
KERNEL32.dll
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .rsrc
4000 .text
So I put the trytoshow.exe, qtguid4.dll, qtcored4.dll and a folder named "Debug_NonRedist", which is from
C:\Program Files\Microsoft Visual Studio 9.0\VC\redist, into a directory. Then I released it to a non-qt-installed pc.
It does not run.
Did I do anything wrong? Thank you.

As winterTTr already pointed out in the comment to your post, it would be important to know what "It does not run" really means.
There could be more dependencies used by the (Qt) Dll's, so I would suggest to have a look at the ouput of Dependency Walker when you start the program to find out what might be missing (you can use the "Profiling" functionality of the program to do that). You can find it here: http://www.dependencywalker.com/

If you want to use a debug version of your program, you should also use the debug version of the relevant dlls. If i remember correctly, there is debug version of Qt dll, such as QtCored4.dll, QtGui4d.dll, and etc.
On the other hand,
if you find "This application has failed to start because the application configuration is incorrect", normally, this is because the debug version runtime library on the target machine may not be same as where you compile it. So, you can use static runtime library link for your application, that should solve this problem.
For vs2010, Under Configuration Properties, C/C++, Code Generation, Runtime Library -> MultiThreaded (/MTd), which is the /MTd compile parameter for cl.exe. You can also try to find how to set it in qt application.

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

make qt5.3.1 .pro file from Visual Studio 2013 project

I wrote a little Qt utility in VS2013. It works fine when running from IDE - even debugging is great. But VS doesn't generate usable exe (error 0xc000007b - "The application was unable start to work correctly", after I've installed all required qt's dll's).
Is there any way to compile everything and correctly from VS? To make really runnable exe?
Or - How can I write correct pro file for qmake?
I tried to write some. qmake generated from it makefile without any erros, but running VS's nmake it gives a "fatal error: U1077 return code '0x2'".
As I think it is problem with linker - even I wrote for all used modules all required QT += lines.
Can anybody help? I think I'm not alone who met this problem.
Thanks.
When you get an error like you got it means you have some dlls missing. You can only find out what dlls are missing using DependencyWalker.
*.pro files can be generated from Visual Studion using the Visual Studio Add-in for Qt4 or with Visual Studio Add-in for Qt5 depending on your Qt version.
If you have a Qt/VS application you want to deploy, AFAIK the following dlls are needed:
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
platforms (folder)
qminimal.dll
qoffscreen.dll
qwindows.dll
icuin52.dll
icudt52.dll
icuuc52.dll
YourApplication.exe
For more information see http://qt-project.org/doc/qt-4.8/deployment-windows.html

compile Qt project without installing qt

I have created a Qt 5 project in Qt Creator.
I want to open and compile this project with Visual Studio 2012 on a computer that doesn't have anything about Qt installed. How can I make the qt libraries follow with my project ?
There is also a Visual Studio plugin enabling Qt projects to be build inside Visual Studio IDE as for example this one :
Visual Studio Add-in 1.2.2 for Qt5
(supports versions 2008, 2010 and 2012, does not work with the Express edition)
Qt Project other downloads
With this Add-in and a Qt SDK version for Visual Studio you don't need to install or build with the Qt Creator IDE.
But as drescherjm said the installation of a minimal Qt SDK is further a necessary dependency.
You can use cmake to resolve dependencies to the qt dll files. For example put dynamic libraries in a include-qt5 folder and include the directory in your CMakeLists as follows,
include_directories ("/include-qt5")
To run your program, you need to copy appropriate dll files next to to your executable (you can use windeployqt to do so).
Note! To use qt classes in your code use relative path to the corresponding header files such as #include <QtWidgets/QMainWindow> and so on. You may need to add the following directives in your code to specify the library that you want the linker to search for,
#if defined(NDEBUG)
#pragma comment(lib, "Qt5Widgets.lib")
#else
#pragma comment(lib, "Qt5Widgetsd.lib")
#endif

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

Accessing NI-VISA from Qt C++ 4.7

I am developing a Windows (7) application using Qt (4.7.0) to call some methods in a DLL (NI visa32.dll) to communicate with instruments through the GPIB port. The manufacturer's header file is also available (visa.h).
In the project file, I tried adding the path and library reference to the original places where the files are located at as:
INCLUDEPATH += "C:/Program Files/National Instruments/Shared/CVI/Include"
LIBS += "C:/Windows/System32/visa32.dll"
but, I get the compilation error:
collect2: ld returned 1 exit status
Following the instructions in Importing a DLL into Qt, I created a "visa.a" from the "visa32.dll", and copied them to a subfolder "visa/lib", and added the path and library to the project file:
INCLUDEPATH += visa/include
LIBS += -Lvisa/lib
LIBS += -lvisa.a
I tried also with -lvisa or -lvisa.dll, but in all the cases I get also another compilation error saying that the -lvisa, -lvisa.a or -lvisa.dll is not found. I edited the original header file "visa.h", and prefixed with Q_DECL_IMPORT every object in the file, and also made sure that the extern "C" statement be present.
I include the reference to the header file in the application as:
#include "visa.h"
and note that the compiler does recognize the referenced objects belonging to the visa.h file.
Any help to solve this compilation error will be greatly appreciated.
I also tried with Visual C++ (2010) following the instructions of DLL References in Visual C++. In this case, I do not get any compilation error, but linking errors. For example:
AgiE364X.obj: error LNK2019: unresolved external symbol
"extern "C" long __stdcall viClose(unsigned long)"
being viClose a called method in NI-VISA.
I would prefer to use Qt C++ instead of Visual C++, though.
Thanks in advance.
I'm not sure since I'm new to Qt myself but here are some guesses: I noticed you have a space in INCLUDEPATH string. Also, LIBS += -Lvisa/lib has a capitol L (is this correct?). I'm not saying this is your problem but perhaps worth a try. The last thing that comes to mind is that if you're using Qt Creator only partially type #include "visa.h" and see if auto complete can complete it for you. If it can, than prob the rest is OK. Trigger auto-complete with Ctrl+Space. I've noticed that when I mess up the paths auto-complete is a good gauge for this sort of thing.
There are two types of library of VISA provided by NI: the one is compiled by borland c++, the other is compiled by microsoft vc++.
As for Qt, you can use Qt which should be compiled by MSVC, to link the visa32.lib which is compiled by MSVC too. And it MUST link .lib instead of .dll, The MSVC library of VISA is in "C:\Program Files\IVI Foundation\VISA\WinNT\lib\msc" by default.
The include directory is C:\Program Files\IVI Foundation\VISA\WinNT\include by default.
In fact, the above information can be known from VISA example after you install the device driver.

Resources