Qt5 - Windows :Windows cannot find executable - c++

I am trying to build a project using Windows 10 and Qt5.12. The small program is using the smtp protocol available here. I can confirm that on my Windows I have the OpenSSL 1.1.1c 28 May 2019. On my Ubuntu 19.04 the same exact program compiles and run as usual but not on Windows.
I git clone my repository into Windows, followed successfully this post and the program builds correctly.
The problem is that when I run it, it cannot find the executable and is asking for it as it is possible to see from the print screen below:
here is my .pro file:
QT += quick quickcontrols2 concurrent network core gui
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
TARGET = SMTPEmail
DEFINES += SMTP_BUILD
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
progressbardialog.cpp \
robot.cpp \
robotmanager.cpp \
settings/emailaddress.cpp \
settings/mimeattachment.cpp \
settings/mimecontentformatter.cpp \
settings/mimefile.cpp \
settings/mimehtml.cpp \
settings/mimeinlinefile.cpp \
settings/mimemessage.cpp \
settings/mimemultipart.cpp \
settings/mimepart.cpp \
settings/mimetext.cpp \
settings/quotedprintable.cpp \
settings/smtpclient.cpp \
user.cpp \
usermanager.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
HEADERS += \
progressbardialog.h \
robot.h \
robotmanager.h \
settings/SmtpMime \
settings/emailaddress.h \
settings/mimeattachment.h \
settings/mimecontentformatter.h \
settings/mimefile.h \
settings/mimehtml.h \
settings/mimeinlinefile.h \
settings/mimemessage.h \
settings/mimemultipart.h \
settings/mimepart.h \
settings/mimetext.h \
settings/quotedprintable.h \
settings/smtpclient.h \
settings/smtpexports.h \
user.h \
usermanager.h
On my Desktop it is created automatically the build folder and thought that the executable would have been here. Below I Am also attaching a print screen of what is inside the build folder:
Originally this project was deployed on Ubuntu and that gave me no problem. I git clone that repo into my Windows, added the missing SMTP_BUILD but I can't fine the executable that the window in the print screen is asking. What am I missing for this final step?
Thank you very much for pointing in the right direction.

As shown in the image of your .pro you are using TEMPLATE = lib whose objective is to create a library whose product is a .dll, .so, etc. that is not an .exe.
If you want to generate an executable you must use:
TEMPLATE = app
Plus:
To make it easier to include the library in your project, I have created this project whose objective is to provide a .pri that is easy to link to any project with .pro. To do this you must follow the following steps:
Download the project
Add include(/path/of/SMTPEmail.pri) to your .pro
Includes using #include <SmtpMime>

Related

Qt5 - Windows: VCRUNTIME140D_APP.dll was not found

I am about to deploy a small application on Windows 10. I successfully build and run the application and created the executable file thanks to this post.
The problem I have is that all of a sudden there is a missing .dll. And to be specific the error message after clicking on the .exe to make sure the application was working to my surprise was the one below:
VCRUNTIME140D_APP.dll was not found
In my debug folder I have the .exe created and had no idea why was asking for that library.
here is my .pro file:
QT += quick quickcontrols2 concurrent network core gui
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
TARGET = SMTPEmail
TEMPLATE = app
DEFINES += SMTP_BUILD
#win32:CONFIG += dll
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
progressbardialog.cpp \
robot.cpp \
robotmanager.cpp \
settings/emailaddress.cpp \
settings/mimeattachment.cpp \
settings/mimecontentformatter.cpp \
settings/mimefile.cpp \
settings/mimehtml.cpp \
settings/mimeinlinefile.cpp \
settings/mimemessage.cpp \
settings/mimemultipart.cpp \
settings/mimepart.cpp \
settings/mimetext.cpp \
settings/quotedprintable.cpp \
settings/smtpclient.cpp \
user.cpp \
usermanager.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
progressbardialog.h \
robot.h \
robotmanager.h \
settings/SmtpMime \
settings/emailaddress.h \
settings/mimeattachment.h \
settings/mimecontentformatter.h \
settings/mimefile.h \
settings/mimehtml.h \
settings/mimeinlinefile.h \
settings/mimemessage.h \
settings/mimemultipart.h \
settings/mimepart.h \
settings/mimetext.h \
settings/quotedprintable.h \
settings/smtpclient.h \
settings/smtpexports.h \
user.h \
usermanager.h
What have I done so far
1) In order to solve this last problem I researched and came across this useful post which also explained the main difference. Although the thing to be noted is that this application will run on Desktop only.
2) I found this version to download vcruntime140_app.dll from which I downloaded the missing library. Unzipped and added to my debug folder as also possible to see from below print screen:
After that I built and run the application but surprisingly I was getting the same exact error despite missing .dll was manually added to the debug folder.
3) I did more research and came across this, this post and also this one. But all of them together didn't help me figure out how to understand what the problem was.
4) I tried to install this version too vcruntime140d.dll from the same site at point 2) above, but still the same result. Missing library VCRUNTIME140D_APP.dll was not found
Last thing I have to notice is that: I downloaded and tried vcruntime140_app.dll then vcruntime140d.dll but I am not able to find a vcruntime140d_app.dll if it exists.
I don't understand why, despite the library is there as is possible to see also here C:\Users\me\OneDrive\Desktop\build-signalsQML-Desktop_Qt_5_12_0_MSVC2017_64bit-Debug\vcruntime140_app.dll the double click on the executable still give the same error.
Thanks for pointing in the right direction for solving this problem.
Solution is to deploy QT dependencies to application folder. After trying a lot, following command solved the issue for me.
C:\Qt\5.12.10\msvc2017_64\bin>windeployqt.exe Project path\Release
This command copies all the required QT dependencies to application folder.
Got the hint from the following link:
QT forum reference

Compiling Qt Tool out of Qt source tree

I am trying to compile canbusutil found in qtserialbus/src/tools/canbusutil out of the Qt source tree. So i just copied the folder to another place and tried to compile. However, I end up with this error:
Project ERROR: Project has no top-level .qmake.conf file.
So I had a look into the canbusutil.pro file:
QT = core serialbus
SOURCES += main.cpp \
readtask.cpp \
canbusutil.cpp \
sigtermhandler.cpp
HEADERS += \
readtask.h \
canbusutil.h \
sigtermhandler.h
load(qt_tool)
Removing the last line leaves me with different errors complaining that some conversions are not allowed or inherited methods not available. Building as part of the Qt sources works just fine. How do I have to adjust the *.pro file to get this to compile out of the Qt source tree.
You need to set the template, and make it a console project:
QT = serialbus
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
SOURCES += main.cpp \
readtask.cpp \
canbusutil.cpp \
sigtermhandler.cpp
HEADERS += \
readtask.h \
canbusutil.h \
sigtermhandler.h
When I try to build qttools\src\linguist\lrelease
the tools are looking for .qmake.conf in the directory that contains the linguist directory. So qttools\src\.qmake.conf
the contents of my .qmake.conf file is:
load(qt_build_config)
CONFIG += qt_example_installs
MODULE_VERSION = 5.8.0
Disclaimer:
My experience with this is on Windows so far. Linux may have different default behavior, and I'm not yet sure which environment variable it would be related to.

qt 5 looking for API-MS-WINxx.dll using GDAL headers

I am developing a C++ Software with OpenCV 3.1 and QT 5 under win7 64Bit System.
The uses compiler is the VS2010 32bit.
I have to use another lib, called GDAL. I built this lib, set PATH environment and set the project properties in QT. As soon as I include a single .h file of GDAL the developed program starts and the instantly ends. QT gives messages like “debugging started” “debugging ended”.
Set break points won’t be reached so the program isn’t even starting. The GDAL lib seems to be included correctly because the used GDAL variables and classes are indicated by the autocomplete function of QT.
I used dependency walker to see if some dll are not loaded. This tools tells me that the following dlls are missing. These dll don’t exist on the harddrive.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-COM-L1-1-1.DLL
API-MS-WIN-CORE-DEBUG-L1-1-1.DLL
API-MS-WIN-CORE-DELAYLOAD-L1-1-1.DLL
API-MS-WIN-CORE-ERRORHANDLING-L1-1-1.DLL
API-MS-WIN-CORE-FILE-L1-2-1.DLL
API-MS-WIN-CORE-FILE-L2-1-1.DLL
API-MS-WIN-CORE-HEAP-L1-2-0.DLL
API-MS-WIN-CORE-HEAP-OBSOLETE-L1-1-0.DLL
API-MS-WIN-CORE-JOB-L2-1-0.DLL
API-MS-WIN-CORE-KERNEL32-LEGACY-L1-1-1.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-2-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L1-2-1.DLL
API-MS-WIN-CORE-LOCALIZATION-OBSOLETE-L1-2-0.DLL`enter code here`
One dll called GPSVC.dll was downloaded from the web. I have read several threads that people have same issues. Some have been fixing these issues by installing redistributable packages. I have all available redistributable packages installed and VS2010 ultimate.
I am getting sick of this problem, does anyone have THE solution to fix? What programs are associated with these listed dlls.
Would downgrading of QT 5 to QT 4 solve the problem.
I haven’t found threads with these issues when QT 4 is used.
Any suggestions are welcome!
Thanks
edit:
just to make all this clear, I would like to give you an overview of my settings.
the windows Path variable looks like this:
E:\opencv31\build\install\x86\vc10\bin;
C:\Qt5\5.5\msvc2010\bin;
E:\GDAL\bin
the .pro file of the qt project:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = AirportExtractor
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
imageanalyzer.cpp \
airport.cpp \
filterslider.cpp \
framewindows.cpp \
scribblearea.cpp \
HEADERS += mainwindow.h \
imageanalyzer.h \
airport.h \
filterslider.h \
framewindows.h \
scribblearea.h \
FORMS += mainwindow.ui \
filterslider.ui \
framewindows.ui \
INCLUDEPATH += E:/GDAL/include/
INCLUDEPATH += E:/opencv31/build/install/include/
LIBS += -LE:/opencv31/build/install/x86/vc10/lib -lopencv_calib3d310d \
-LE:/GDAL/lib -lgdal_i \
I added the following paths to the project settings:
INCLUDE E:\GDAL\include;
LIB E:\GDAL\lib;

Build a 3rd party library from source within an existing Qt project

My project requires a version of zlib that isn't present on all target machines, so I want to build zlib from source in my project. Then when I make my project, it should first build zlib so it can be linked to when compiling my project.
One complication is that zlib requires configure to be run before make can be run.
I'm not even sure where to start here. Is there functionality built in to Qt Creator for importing 3rd party library source code like this, or do I need to code out a custom .pro file?
I tried the "Add Library..." menu that appears when right-clicking on my project, but it doesn't recognize the library - likely because no .pro file exists. I also tried to create a .pro file by File -> New Project -> Import Existing Project, and it's able to compile zlib once configure has been run, but it still doesn't generate a .pro file.
I thought that maybe the subdirs might be useful, but I'm not sure if that is the right route in this situation, and even if it is I am not sure whether I can auto-create the necessary .pro file, or I have to create it myself.
Given the source code for a 3rd party library like zlib, how do I integrate that into an existing Qt project such that I can compile the library from source, and use it in my project?
Yes, you need to create a project file for it. You can find my version below what I used for several projects.
zlib.pro
QT -= core gui
TARGET = zlib
TEMPLATE = lib
# Use this for static zlib rather than the default dynamic
# CONFIG += staticlib
include(zlib.pri)
zlib.pri
HEADERS += \
$$PWD/crc32.h \
$$PWD/deflate.h \
$$PWD/gzguts.h \
$$PWD/inffast.h \
$$PWD/inffixed.h \
$$PWD/inflate.h \
$$PWD/inftrees.h \
$$PWD/trees.h \
$$PWD/zconf.h \
$$PWD/zlib.h \
$$PWD/zutil.h
SOURCES += \
$$PWD/adler32.c \
$$PWD/compress.c \
$$PWD/crc32.c \
$$PWD/deflate.c \
$$PWD/gzclose.c \
$$PWD/gzlib.c \
$$PWD/gzread.c \
$$PWD/gzwrite.c \
$$PWD/infback.c \
$$PWD/inffast.c \
$$PWD/inflate.c \
$$PWD/inftrees.c \
$$PWD/trees.c \
$$PWD/uncompr.c \
$$PWD/zutil.c
INCLUDEPATH += $$PWD
Then in the project file including this one, you can do something like this:
main.pro
# CONFIG += order # If you wanna make sure about order. This is optional.
SUBDIRS += \
zlib \
...
If you wanna go even a bit more advanced with qmake, you can do something like this:
SUBDIRS += \
src_zlib \
src_mylib \
...
src_zlib.subdir = $$PWD/zlib
src_zlib.target = sub-zlib
src_zlib.depends =
src_mylib.subdir = $$PWD/mylib
src_mylib.target = sub-mylib
src_mylib.depends = src_zlib
As you can see this way, you would have a lot more reasonable control among the dependencies regardless the order set. For instance, you could still keep the entries in alphabetical order which is helpful with proper maintenance in the long run.
Then, you will need a line like this in the project file (.pro) of your subproject, let us say "foo", which depends on zlib.
foo.pro
LIBS += -L$${PROJECTROOT}/$${SUBDIR_TO_ZLIB} -lz
# These lines are only option, and you do not necessarily need them.
# win32:LIBNAME = zlib.dll
# unix:LIBNAME = libzlib.so
# PRE_TARGETDEPS += $${PROJECTROOT}/$${BUILD_SUBDIR_LIBS}/$${LIBNAME}
Following are instructions for adding a 3rd party repository to your Qt project and building it from source.
Some are able to add such libraries via Qt Creator, but I could never get that to work. So these are instructions on how to create the necessary .pro and .pri files instead. In this post, I will use zlib as an example, although other libraries should be similar.
Setup Build Order
Since your application depends on this library, we need to ensure that the library is built first. To do this, the 3rd party library and the source code for your application should be in sibling directories.
~/myApp $ ls myApp
src zlib
You probably already have a myApp.pro file that correctly builds your application. I recommend renaming it to src.pro, and you'll see why in the next step.
mv src/myApp.pro src/src.pro
Now you can create a new myApp.pro in the root directory.
~/myApp $ touch myApp.pro
~/myApp $ ls
myApp.pro src zlib
This is a rather simple .pro file that merely says "build zlib before myApp."
# ~/myApp/myApp.pro
TEMPLATE = subdirs
CONFIG += ordered # This tells Qt to compile the following SUBDIRS in order
SUBDIRS = zlib src
Create Library .pro File
Now we need to tell Qt how to build our 3rd party library. We do this by creating a new .pro file:
# ~/myApp/zlib/zlib.pro
TARGET = z # The name of the output library - can be whatever you want
TEMPLATE = lib # Tells Qt that we are compiling a library so the output will be bundled into a .a or .so file
CONFIG += staticlib # Tells Qt that we want a static library, so a .a file. Remove this and you will get a .so file
QMAKE_CFLAGS_WARN_ON -= -Wall # Optional - disable warnings when compiling this library
QMAKE_CXXFLAGS_WARN_ON -= -Wall # Optional - disable warnings when compiling this library
HEADERS += \
crc32.h \
deflate.h \
gzguts.h \
inffast.h \
inffixed.h \
inflate.h \
inftrees.h \
trees.h \
zconf.h \
zlib.h \
zutil.h
SOURCES += \
adler32.c \
compress.c \
crc32.c \
deflate.c \
gzclose.c \
gzlib.c \
gzread.c \
gzwrite.c \
infback.c \
inffast.c \
inflate.c \
inftrees.c \
trees.c \
uncompr.c \
zutil.c
If you are building something other than zlib, just change TARGET to the name of the library, and replace the contents of HEADERS and SOURCES with the files that need to be compiled for your library.
You can go ahead now and test out this .pro file.
~/myApp/zlib/ $ qmake
~/myApp/zlib/ $ make
...
~/myApp/zlib/ $ ls libz.a
libz.a
Yay!
Link The Library Into Your Application
Finally, we need to update the .pro file of your application to link in the 3rd party library. There are two parts to this:
Add library header files to your include path so the compiler can get the defined symbols from there.
Link the static (or shared) library during compile and linking time so the applicable object code can get linked into your application.
First, we'll add the header files into the include path. Add this line to src.pro.
INCLUDEPATH += zlib
This allows you to reference zlib.h in your code like so:
#include "zlib.h"
Otherwise, you would have to specify the full relative path of the header like this:
#include "zlib/zlib.h"
If you're fine with the second method, then there should be no need to update the INCLUDEPATH variable.
Second, we need to add the arguments the linker needs to find the static (or shared) library itself. Add this line to src.pro.
LIBS += -L$$PWD/../zlib -lz
The first part (-L$$PWD/../zlib) says that the folder containing the library is at ../zlib, which should be correct since zlib is a sibling folder to src. The second part (-lz) says that the name of the library is z. The linker infers from this that the library is actually located in the file libz.a.
Done
At this point, you may have to clean your build by doing a make distclean. But from there you should be able to build your project with the 3rd party library included by going to your base directory and running qmake and make.
cd ~/myApp
qmake -r
make
Note: Big thanks go to #LaszloPapp for getting this process started. Much of the source material for this answer came from his answer.
Alternatively if you are using QT Creator you could try to investigate "Project Settings" -> "Add Build Step" -> "Custom build step" and add script file there.
This could help to build lib before and then you just need to link it to your project.
I'm not sure, but most likelly you could pass the compilers settings like an argument to this script. I'm triing to solve it right now.

How to reference 3rd party dlls/libraries in Qt projects

Been trying to figure this out for an hour now. What I have is a simple Qt Project open in Qt Creator. What I would like to do is use the SDL library (dll) with my Qt project.
In visual Studio, what I would normall do is add a reference to this dll using VS tool that provides for that. In Qt creator, I opened the .pro file for my project, and added a LIB entry for the STD dll
# Add more folders to ship with the application, here
folder_01.source = qml/BoxGame
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
symbian:TARGET.UID3 = 0xEED812B5
# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF
# Allow network access on Symbian
symbian:TARGET.CAPABILITY += NetworkServices
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
LIBS += C:\Users\vata\Desktop\DskProj\Dsk-build-desktop\debug\SDL.dll
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
blockboxes.cpp \
block.cpp \
boxengine.cpp \
boxgame.cpp \
point.cpp \
gamecontroller.cpp \
gamecontrollermod.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()
HEADERS += \
blockboxes.h \
block.h \
boxengine.h \
boxgame.h \
Globals.h \
point.h \
gamecontroller.h \
gamecontrollermod.h \
controller.h
However, that does not seem to include the Library in Qt for my use. When I compile, I still get an SDL.h: No such file or directory error message. Would appreciate any help in figuring this out and probably learning for the future as I intend to use Qt more often than not for my development work.
Running build steps for project Tetris...
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe" clean
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug clean
SDL.h is a C header file, not a library. For the compiler to find it, you need to add its directory to qmake's INCLUDEPATH. For example:
INCLUDEPATH += C:/Dir/Where/SDL/Headers/Are/Found
(Tip: you can use / instead of \ to stay clear of possible interpretations of \ as an escape character.)
Try something like:
LIBS += -LC:\\Users\\vata\\Desktop\\DskProj\\Dsk-build-desktop\\debug -lsdl