project crash occur when run in release mode but working properly in debug mode.
-
Here i have attached my project pro file code and a pushbutton code. My main issue is when i try to run my project in release mode build and run successfully but when i click a particular pushbutton project is crashed at the same time when i run it in debug mode it completely working properly. please provide me different possibilities to recover this issue.
Pro code:
QT += core gui sql QT += network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport TARGET = BCUID TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use 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 CONFIG += c++17 CONFIG += extserialport SOURCES += \ main.cpp \ mainwindow.cpp \ HEADERS += \ mainwindow.h \ FORMS += \ mainwindow.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target QMAKE_CXXFLAGS_RELEASE += -Os QMAKE_CFLAGS_RELEASE -= -O2 INCLUDEPATH += /usr/local/include LIBS += -L/usr/local/lib -lwiringPi -liir RESOURCES += \ icons.qrc
/////That crash issue in this particular pushbutton below provided the complete code//////
int MainWindow::on_pushButton_148_clicked() { ui->label_211->setText("Status : "); ui->label_340->clear(); QDir pathDir("/home/pi/Biochemistry_Versions"); if (pathDir.exists()) { QDir directory("/home/pi/Biochemistry_Versions"); directory.removeRecursively(); QProcess *myprocess = new QProcess(this); QDir Direct ("/home/pi/"); qDebug() << Direct ; myprocess->setWorkingDirectory("/home/pi/"); myprocess->start("git clone https://github.com/Instruments04/Biochemistry_Versions.git"); if (!myprocess->waitForStarted()) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); return 1; } qDebug() << "No Error "; if ( !myprocess->waitForFinished( -1 ) ) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); return 0; } else { if(myprocess->exitCode()==0) { QFile file("/home/pi/Biochemistry_Versions/README.md"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); while (!in.atEnd()) { QString data = in.readLine(); bool ok = false; double Version = data.toDouble(&ok); if (ok) { double old_version = ui->label_340->text().toDouble(); if(Version>old_version) { ui->label_211->setText("Status : "); ui->label_340->setText("<font color='green'>✅ The new version of the software is now available, kindly upgrade to it.</font>"); } else { ui->label_211->setText("Status : "); ui->label_340->setText("<font color='blue'>\u26A0 The software has already been updated to the latest version.</font>"); } } } file.close(); } else { qDebug()<<"File Not Found"; } } else if(myprocess->exitCode()==128) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); } } delete myprocess; // Release memory when you're done } else { QProcess *myprocess = new QProcess(this); QDir Direct ("/home/pi/"); qDebug() << Direct<<"No file" ; myprocess->setWorkingDirectory("/home/pi/"); myprocess->start("git clone https://github.com/Instruments04/Biochemistry_Versions.git"); if (!myprocess->waitForStarted()) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); return 1; } qDebug() << "No Error "; if ( !myprocess->waitForFinished( -1 ) ) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); return 0; } else { if(myprocess->exitCode()==0) { QFile file("/home/pi/Biochemistry_Versions/README.md"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); while (!in.atEnd()) { QString data = in.readLine(); bool ok = false; double Version = data.toDouble(&ok); if (ok) { double old_version = ui->label_340->text().toDouble(); if(Version>old_version) { ui->label_211->setText("Status : "); ui->label_340->setText("<font color='green'>✅ The new version of the software is now available, kindly upgrade to it.</font>"); } else { ui->label_211->setText("Status : "); ui->label_340->setText("<font color='blue'>\u26A0 The software has already been updated to the latest version.</font>"); } } } file.close(); } else { qDebug()<<"File Not Found"; } } else if(myprocess->exitCode()==128) { handleProcessError1(myprocess, "The process was stopped due to a poor WiFi signal."); } } delete myprocess; // Release memory when you're done } } void MainWindow::handleProcessError1(QProcess *process, const QString &errorMessage) { ui->label_211->setText("Status : "); ui->label_340->setText("<font color='red'>⚠" + errorMessage + "</font>"); qDebug() << "Error : " << process->errorString(); }
-
@Mohan-Raj This is a lot of code to look at. You should at least try to find out which line of code causes the crash.
Unrelated: the way you're calling external command is not going to work. Please check QProcess documentation to see how to use it properly.
-
Thanks for your reply. Actually project is very large this button is point percent of it.
Another one thing..... i have tried all this button function in a separate project with a single pushbutton. its working properly in release mode but its not working when run it in my whole project. And i have checked almost that there is no memory leakage issue is there. -
Hi,
The usual suspect when debug works and release die is: you are not properly initializing your pointers in your constructor. Debug mode sets them to 0 but not release. Check them all.