Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. project crash occur when run in release mode but working properly in debug mode.
Forum Updated to NodeBB v4.3 + New Features

project crash occur when run in release mode but working properly in debug mode.

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
5 Posts 3 Posters 345 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohan Raj
    wrote on last edited by Mohan Raj
    #1

    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();
    }
    jsulmJ 1 Reply Last reply
    0
    • M Mohan Raj

      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();
      }
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mohan Raj
        wrote on last edited by
        #3

        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.

        WhatsApp Image 2023-11-07 at 9.12.48 PM.jpeg

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mohan Raj
          wrote on last edited by
          #4

          Sorry for inconvenience. i have posted multiple button codes wrongs. now i edited with the particular button code. now it looks simple when compared with previous.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved