Release .exe doesn't start and does not give any errors
-
Hi, I have been working on a large project for quite some time now, every couple of weeks I do a release build and add the new .exe file on a drive folder that contains all the required .dlls, essentially deploying incrementing versions of the project. This has been working fine for the past months. I recently attempted to the same exact thing, where I build a release build and copy the executable to the drive folder (which has all the dlls that the previous versions required) , however this time, when double clicking the executable it simply does not start, no error messages, nothing. When I double click any of the previous versions they start up fine.
It is worth noting that I did a somewhat big refactor of the project structure, but it was mostly architectural changes of the inheritance structure of the classes within the project. And I also changed the name of the .pro file, not sure if this would cause a problem.
I really would appreciate some help on this.
-
Hi,
Are you able to start it on your own machine once deployed ?
Did you check on the command line whether there's an error message there ?
-
Strange... Do you have any early exit code path that could finish the program before it shows any GUI ?
-
@SGaist said in Release .exe doesn't start and does not give any errors:
Do you have any early exit code path that could finish the program before it shows any GUI ?
No, main.cpp simply starts mainwindow.cpp and the user needs to make a selection on the MainWindow before anything happens
-
Then let's go with the basics.
Can you remove everything from your code and just show an empty QWidget ?
-
@SGaist said in Release .exe doesn't start and does not give any errors:
Can you remove everything from your code and just show an empty QWidget ?
Okay, if I understood you correctly I stripped everything from the mainwindow files (.cpp, .h and .ui) and just left it as an empty widget. (All the other files are still included in the .pro file however) and I still have the same issue
-
So, I tried deploying from scratch, I
- copied the release .exe to an empty folder "release",
- I ran the following command, from the respective compiler directory,
windeployqt.exe path_to_directory\release
- a bunch of .dlls were created, tried running, got a few errors about missing .dlls
- added the missing .dll files
- tried running again, I got the same result... no errors and the application doesn't start up
- copied the previous release .exe version to the same "release" directory and tried running it, runs fine
I have no clue what I'm missing here
-
@SGaist said in Release .exe doesn't start and does not give any errors:
Can you remove everything from your code and just show an empty QWidget ?
I just removed all the files from the .pro file except the mainwindow files and main.cpp, and the now the app runs when placed in the deployment folder..
It seems the problem is in one of the files, however I have over 200 files and there are many dependecies, so I am not sure how to go about debugging this
-
Okay so after a tedious debugging session, I found the file with the problem. I have a file
globals.h
that defines a bunch of global variables, objects & functions using theextern
keyword. Inglobals.cpp
I instantiate the variables and objects and implement the functions, initializing some of the variables to set default values. This file is included in almost every file in the project, and it seems that it is where the problem lies.This file was recently added to the project in the most recent version and was not included in previous ones. This file is crucial to the project, I am not sure why its causing this problem,
the header file looks something like this:
#ifndef GLOBALS_H #define GLOBALS_H #include <QDateTime> #include "serialport.h" #include "thread_one.h" ... extern int debug; extern QString name; //* Global Objects *// extern SerialPort serial; extern thread_one* threadOne; ... //* Global Variables *// extern int rate; extern int initialRate; extern double total; extern QByteArray data; //data recieved in port ... //* Global Functions *// extern QString date(); //current date extern QString time(); //current time extern double distance(int secs, int speed); ... #endif // GLOBALS_H
and the implementation file:
#include "globals.h" int debug = 1; QString name; SerialPort serial; thread_one* threadOne = new thread_one; int rate = 10; int initialRate = 0; double total = 0; QByteArray data; QString date() { return QDateTime::currentDateTime().date().toString("MM:dd:yyyy").replace(":", "/");} QString time() { return QDateTime::currentDateTime().time().toString("hh:mm:ss"); } double distance(int secs, int speed) { return distanceTraveled = static_cast<double>(speed * secs/3600); }
I would greatly appreciate some help
-
Several things:
- Do not use extern, use a namespace. You can declare your variables and functions there and the define them in your cpp files.
- Global objects are usually a bad sign with only a few exceptions. Many abuse them to pass these objects around in an easy way rather that build a proper architecture on top of them.
In fact it seams that the handling of the serial port and its data is done entirely through global objects which is a bad idea.
Implementation wise:
@Adham said in Release .exe doesn't start and does not give any errors:
QString date() { return QDateTime::currentDateTime().date().toString("MM:dd:yyyy").replace(":", "/");}
There's no need for that replace. Just use the slash directly in your format string.
Also, QDate directly provides currentDate so you are making more calls than actually necessary.
One last thing: date and time are not really good names for these functions. They in fact return a formatted string with the current date for the former and the current time for the later. This is not really maintenance friendly.
-
@SGaist
Thank you for your response.
I actually got assigned this project after it was developed for a couple of years and it was a disastrous mess, and my task was to maintain and upgrade it to follow a more proper object-oriented architecture. It's too big to simply rewrite from scratch and I'm learning more as I go.Now, for using a namespace instead of extern statements, as I said earlier these are global variables, meaning they need to have the same value across all files, when I removed the extern statements and placed all the variables in a namespace called "globals" and used this namespace in all the other files
using namespace globals;
I got a ton of "multiple definition" errors.I searched online and most, if not all, of the answers seem to point towards using the extern keyword to be able to achieve what I want. Using a namespace or not, it seems I would still need to declare the variables as extern to indicate that they may be included multiple times. Unless you mean to put all my code, across all files, inside the namespace, which doesn't seem like the right thing to do.
I still do no understand why my current implementation works fine when building and running in Qt but does not start when I deploy it.
So I am back to where I started..