PDA

View Full Version : Qt app runs in creator but crashes from command line



emp1953
16th June 2017, 20:06
I built an app with Qtcreator with a gui. it compiles without warnings or errors and runs perfectly from Creator. When I compile from the command line, one of the button functions causes the app to crash. Does the app need something special from Qtcreator in order to run from the command line??

Thanks in Advance.

d_stranz
16th June 2017, 21:17
A crash in release mode usually means you are accessing a NULL or uninitialized pointer, that you haven't properly initialized a variable and use it before it is initialized, that you are trying to load a resource or something and then try to use it before checking if loading was successful, or any number of other programming errors. A crash is almost always your problem.

Running in a debugger under any IDE is different from running on the command line. The debugger generally initializes variables to known values so you can recognize them as such when debugging. Qt Creator also sets up an environment where resources and other things can be found when needed. Neither of these is true of the command line.

joovoo
25th June 2017, 11:34
Good Morning d_stranz! First excuse me to bother u whith my poor nknowledge in english.I get a similar problem: My Qt program crashe whithout the warning or error of the compiler after running perfectly in Qt creator.My program consist of ask names of five students using a QInputDialgue and try to put those names in a vertical alignment in a window, using a QFormLayout of QLabel and QDoubleSpinBox.This is the code :


#include <QObject>
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QDoubleSpinBox>
#include <QLabel>
#include <QInputDialog>
#include <QString>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QVector>
#include <QVBoxLayout>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget fenetre;
QVector<QFormLayout*> layout(5);
QVector<QDoubleSpinBox*> note(5);
QVector<QString> liste(5);
QVBoxLayout *vlayout=new QVBoxLayout;
QString eleve;
bool ok(false);
int i(0);
for(i=0;i<5;i++){eleve=QInputDialog::getText(&fenetre,
"Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);
if(ok&&!eleve.isEmpty()){liste[i]=eleve;}
else {i--;}}
for(i=0;i<5;i++){(layout.at(i))->addRow(liste.at(i),note.at(i));}for(i=0;i<5;i++){vlayout->addLayout(layout.at(i));}
fenetre.setLayout(vlayout);
fenetre.show();
return app.exec();
}

This is the message displayed after i've put all names required by the QInputDialogue:


Démarrage de C:\Users\yayah\Documents\build-TEST-Desktop_Qt_5_6_2_MinGW_32bit-Debug\debug\TEST.exe...
Le programme s'est terminé subitement.
C:\Users\yayah\Documents\build-TEST-Desktop_Qt_5_6_2_MinGW_32bit-Debug\debug\TEST.exe crashed.

Please help me!!!!!

d_stranz
26th June 2017, 01:56
Your QVector< QFormLayout > and QVector< QSpinBox > are declared but they are never initialized. When you try to use them in line 30, your program crashes.

But there is so much else wrong with your program that even if you did initialize the vectors correctly, your program probably still would not run.

joovoo
26th June 2017, 17:49
Ok! THanks for the answer. So what are those wrong things and how can i initialiZe thoses vectors please?

d_stranz
26th June 2017, 18:08
Look, you've hijacked a thread that wasn't yours to start with, so I am not going to reply any more to it.

If you don't know the difference between declaring and initializing, you need to go back to your C++ book and look it up. We're not here to teach basic C++.

joovoo
27th June 2017, 08:32
Ok !Excuse me for doing that...! So i do stop that now.