Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt program crash why?
Forum Updated to NodeBB v4.3 + New Features

Qt program crash why?

Scheduled Pinned Locked Moved Solved General and Desktop
38 Posts 8 Posters 5.2k Views 1 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #2

    @Wasee said in Qt program crash why?:

    running its crashes.

    Use a debugger, see where it crashes, fix it.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    3
    • WaseeW Wasee

      Dear all;
      I code following when I called this function in timer event or any other place then my program crashes why?```
      /@
      void secbox::dds_control(){

                 QProcess DD;
                 DD.start("sudo devmem2 0x80000000");
                 DD.waitForFinished(); // will wait forever until finished
                QString dds (DD.readAllStandardOutput());
                dds = dds.replace("(","").replace(")","").replace(":","");
                auto split1 = dds.split("0x");
                QString dds_en("%1:%2");
                dds_en = dds_en.arg(split1.at(1).toLongLong(nullptr,16)).arg(split1.at(2).toLongLong(nullptr,16));
                //str2 =QString::number(split1.at(2),16);
                     qDebug()<<"Detected:"<<dds_en;
                  dds_control();
                  if(dds_en=="0:0"){
                      QProcess p1 ;
                      p1.startDetached("/bin/bash", QStringList() << "-c" << "/home/ijaz/bashScripts/script1.sh");
                      QProcess Rx_CF;
                      Rx_CF.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
                      Rx_CF.waitForFinished(-1); // will wait forever until finished
                      Rx_CF_read =Rx_CF.readAllStandardOutput();
                      //QString ac = Rx_CF_read;
                  }
                  else{
                       ac = Rx_CF_read;
                      QString ab="cd /sys/bus/iio/devices/iio\:device1 && echo";
                      //QString ac=ui->CF_new->text();
      
                     // qDebug() << "third arry = " << third_arry ;
      
                      QString ad = " > out_altvoltage1_TX_LO_frequency";
                                   ab.append(ac) ;
                      QProcess band1_on;
                      //  band1_on.start(band1_1.append(third_arry));
                       band1_on.start(ab.append(ad));
                       band1_on.waitForFinished(-1); //
                        qDebug() << "band1_on  = " << ab ;
                       // //////////////////////////////
                  }
      

      @/
      When I run the mu application after running its crashes.
      thanks

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by SGaist
      #3

      @Wasee said in Qt program crash why?:
      probably here:

      dds_en.arg(split1.at(1).toLongLong(nullptr,16)).arg(split1.at(2).toLongLong(nullptr,16));

      you do not check the length of the vector before accessing the 2nd and 3rd index of it.

      Don't trust, exercise control !

      [edit: fixed missing word SGaist]


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • WaseeW Offline
        WaseeW Offline
        Wasee
        wrote on last edited by
        #4

        @J-Hilk thanks for your reply
        I code following line
        /@
        dds_en =QString::number(split.at(1),16);
        @/
        Its give this error.
        error: no matching function for call to ‘QString::number(const QString&, int)’
        dds_en =QString::number(split.at(1),16);
        ^

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

          Hi,

          Read the documentation of the method. It expects one of C++ numeral types not a QString.

          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
          1
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #6

            Further to @J.Hilk's suggestion, it would fail here because either the output of devmem2 was not as expected, or because it failed outright (as it does on my machine).

            Assuming devmem2 works at all, you are expecting something like this on stdout:

            /dev/mem opened.
            Memory mapped at address 0x7f5c34dc3000.
            Value at address 0x0 0x7f5c34dc3000 0xF000EEF3
            

            This is what your split1 array looks like:

            (
            "/dev/mem opened.\nMemory mapped at address ", 
            "7f5c34dc3000.\nValue at address ", 
            "0 ", 
            "7f5c34dc3000 ", 
            "F000EEF3\n"
            )
            

            So, split1 is not what you are expecting and one or both attempts to convert toLongLong() is probably failing. What you do with that information later is not what you expect.

            If devmem2 fails completely then the split1 array contains only a single entry and the split.at() calls seg fault.

            1 Reply Last reply
            1
            • WaseeW Wasee

              @J-Hilk thanks for your reply
              I code following line
              /@
              dds_en =QString::number(split.at(1),16);
              @/
              Its give this error.
              error: no matching function for call to ‘QString::number(const QString&, int)’
              dds_en =QString::number(split.at(1),16);
              ^

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #7

              @Wasee
              you need to check the length of your split vector, I don't see that run your corrected code ?

              if(auto split1 = dds.split("0x"); split1.size() >3) {
                  //your code
                  QString dds_en("%1:%2");
                            dds_en = dds_en.arg(split1.at(1).toLongLong(nullptr,16)).arg(split1.at(2).toLongLong(nullptr,16));
                            //str2 =QString::number(split1.at(2),16);
                                 qDebug()<<"Detected:"<<dds_en;
                              dds_control();
              } else {
                  qDebug() << "String was not the expected format/length";
              }
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • WaseeW Offline
                WaseeW Offline
                Wasee
                wrote on last edited by
                #8

                @J-Hilk I run the above code it giving me error at this line.

                if(auto split1 = dds.split("0x") && split1.size() >3)

                use of split1 before deduction

                I remove your ; between your code lines giving error expected token ';' then I replace it with "&&"
                thanks

                Christian EhrlicherC J.HilkJ 2 Replies Last reply
                0
                • WaseeW Wasee

                  @J-Hilk I run the above code it giving me error at this line.

                  if(auto split1 = dds.split("0x") && split1.size() >3)

                  use of split1 before deduction

                  I remove your ; between your code lines giving error expected token ';' then I replace it with "&&"
                  thanks

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Wasee This is a c++17 feature - either enable c++17 or write move auto split1 = dds.split("0x") outside the if statement.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  Christian EhrlicherC 1 Reply Last reply
                  1
                  • WaseeW Wasee

                    @J-Hilk I run the above code it giving me error at this line.

                    if(auto split1 = dds.split("0x") && split1.size() >3)

                    use of split1 before deduction

                    I remove your ; between your code lines giving error expected token ';' then I replace it with "&&"
                    thanks

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #10

                    @Wasee

                    if(auto split1 = dds.split("0x"); split1.size() >3) {
                    

                    is most definitely the correct syntax, I even test compiled a small minimal example.

                    can you post what you actually wrote ? and what version of c++ did you set? the init statement is a c++17 feature. If you're using an older version, you have to move that before the if case


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    0
                    • WaseeW Offline
                      WaseeW Offline
                      Wasee
                      wrote on last edited by
                      #11

                      @J-Hilk Hi;
                      /@

                                 QProcess DD;
                                 DD.start("sudo devmem2 0x80000000");
                                 DD.waitForFinished(); // will wait forever until finished
                                QString dds (DD.readAllStandardOutput());
                                dds = dds.replace("(","").replace(")","").replace(":","");
                      
                              if( ( auto split1 = dds.split("0x"); split1.size()>3{
                                  if(dds_en=="0:0"){
                                      QProcess p1 ;
                                      p1.startDetached("/bin/bash", QStringList() << "-c" << "/home/ijaz/bashScripts/script1.sh");
                                      QProcess Rx_CF;
                                      Rx_CF.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
                                      Rx_CF.waitForFinished(-1); // will wait forever until finished
                                      Rx_CF_read =Rx_CF.readAllStandardOutput();
                                      //QString ac = Rx_CF_read;
                                  }
                                  else{
                                       ac = Rx_CF_read;
                                      QString ab="cd /sys/bus/iio/devices/iio\:device1 && echo";
                                      //QString ac=ui->CF_new->text();
                      
                                      qDebug() << "Tx_LO Tunned ON= " << ac ;
                      
                                      QString ad = " > out_altvoltage1_TX_LO_frequency";
                                                   ab.append(ac) ;
                                      QProcess band1_on;
                                      //  band1_on.start(band1_1.append(third_arry));
                                       band1_on.start(ab.append(ad));
                                       band1_on.waitForFinished(-1); //
                                        qDebug() << "band1_on  = " << ab ;
                                       // //////////////////////////////
                                QString dds_en("%1:%2");
                               // dds_en = dds_en.arg(split.at(1).toLongLong(nullptr,16)).arg(split.at(2).toLongLong(nullptr,16));
                                dds_en =QString::number(split.at(1),16);
                                     qDebug()<<"Detected:"<<dds_en;
                                 // dds_control();
                      

                      }
                      } else{
                      qDebug() << "String was not the expected format/length";
                      }
                      @/

                      J.HilkJ JonBJ 2 Replies Last reply
                      0
                      • WaseeW Wasee

                        @J-Hilk Hi;
                        /@

                                   QProcess DD;
                                   DD.start("sudo devmem2 0x80000000");
                                   DD.waitForFinished(); // will wait forever until finished
                                  QString dds (DD.readAllStandardOutput());
                                  dds = dds.replace("(","").replace(")","").replace(":","");
                        
                                if( ( auto split1 = dds.split("0x"); split1.size()>3{
                                    if(dds_en=="0:0"){
                                        QProcess p1 ;
                                        p1.startDetached("/bin/bash", QStringList() << "-c" << "/home/ijaz/bashScripts/script1.sh");
                                        QProcess Rx_CF;
                                        Rx_CF.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
                                        Rx_CF.waitForFinished(-1); // will wait forever until finished
                                        Rx_CF_read =Rx_CF.readAllStandardOutput();
                                        //QString ac = Rx_CF_read;
                                    }
                                    else{
                                         ac = Rx_CF_read;
                                        QString ab="cd /sys/bus/iio/devices/iio\:device1 && echo";
                                        //QString ac=ui->CF_new->text();
                        
                                        qDebug() << "Tx_LO Tunned ON= " << ac ;
                        
                                        QString ad = " > out_altvoltage1_TX_LO_frequency";
                                                     ab.append(ac) ;
                                        QProcess band1_on;
                                        //  band1_on.start(band1_1.append(third_arry));
                                         band1_on.start(ab.append(ad));
                                         band1_on.waitForFinished(-1); //
                                          qDebug() << "band1_on  = " << ab ;
                                         // //////////////////////////////
                                  QString dds_en("%1:%2");
                                 // dds_en = dds_en.arg(split.at(1).toLongLong(nullptr,16)).arg(split.at(2).toLongLong(nullptr,16));
                                  dds_en =QString::number(split.at(1),16);
                                       qDebug()<<"Detected:"<<dds_en;
                                   // dds_control();
                        

                        }
                        } else{
                        qDebug() << "String was not the expected format/length";
                        }
                        @/

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #12

                        @Wasee said in Qt program crash why?:

                        if( ( auto split1 = dds.split("0x"); split1.size()>3{

                        remove one of the opening ( and add the missing closing ) before the {


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        0
                        • WaseeW Offline
                          WaseeW Offline
                          Wasee
                          wrote on last edited by
                          #13

                          @J-Hilk Hi;
                          I added this but got error expected token ';'
                          if( auto split1 = dds.split("0x"); split1.size()>3){
                          //my code
                          }

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @Wasee This is a c++17 feature - either enable c++17 or write move auto split1 = dds.split("0x") outside the if statement.

                            Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            I added this but got error expected token ';'

                            @Christian-Ehrlicher said in Qt program crash why?:

                            This is a c++17 feature

                            Repeating myself...

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            J.HilkJ 1 Reply Last reply
                            1
                            • Christian EhrlicherC Christian Ehrlicher

                              I added this but got error expected token ';'

                              @Christian-Ehrlicher said in Qt program crash why?:

                              This is a c++17 feature

                              Repeating myself...

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #15

                              @Christian-Ehrlicher
                              its the wrong error message for that, it should be
                              language feature 'init-statements in if/switch' requires compiler flag '/std:c++17'

                              the missing ; is somewhere else in the ops code.


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              1 Reply Last reply
                              0
                              • WaseeW Wasee

                                @J-Hilk Hi;
                                /@

                                           QProcess DD;
                                           DD.start("sudo devmem2 0x80000000");
                                           DD.waitForFinished(); // will wait forever until finished
                                          QString dds (DD.readAllStandardOutput());
                                          dds = dds.replace("(","").replace(")","").replace(":","");
                                
                                        if( ( auto split1 = dds.split("0x"); split1.size()>3{
                                            if(dds_en=="0:0"){
                                                QProcess p1 ;
                                                p1.startDetached("/bin/bash", QStringList() << "-c" << "/home/ijaz/bashScripts/script1.sh");
                                                QProcess Rx_CF;
                                                Rx_CF.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
                                                Rx_CF.waitForFinished(-1); // will wait forever until finished
                                                Rx_CF_read =Rx_CF.readAllStandardOutput();
                                                //QString ac = Rx_CF_read;
                                            }
                                            else{
                                                 ac = Rx_CF_read;
                                                QString ab="cd /sys/bus/iio/devices/iio\:device1 && echo";
                                                //QString ac=ui->CF_new->text();
                                
                                                qDebug() << "Tx_LO Tunned ON= " << ac ;
                                
                                                QString ad = " > out_altvoltage1_TX_LO_frequency";
                                                             ab.append(ac) ;
                                                QProcess band1_on;
                                                //  band1_on.start(band1_1.append(third_arry));
                                                 band1_on.start(ab.append(ad));
                                                 band1_on.waitForFinished(-1); //
                                                  qDebug() << "band1_on  = " << ab ;
                                                 // //////////////////////////////
                                          QString dds_en("%1:%2");
                                         // dds_en = dds_en.arg(split.at(1).toLongLong(nullptr,16)).arg(split.at(2).toLongLong(nullptr,16));
                                          dds_en =QString::number(split.at(1),16);
                                               qDebug()<<"Detected:"<<dds_en;
                                           // dds_control();
                                

                                }
                                } else{
                                qDebug() << "String was not the expected format/length";
                                }
                                @/

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #16

                                @Wasee said in Qt program crash why?:

                                if( ( auto split1 = dds.split("0x"); ...

                                The doubled (s are wrong, and the cause of the error message. I think @J-Hilk has already pointed this out earlier....

                                1 Reply Last reply
                                0
                                • WaseeW Offline
                                  WaseeW Offline
                                  Wasee
                                  wrote on last edited by
                                  #17

                                  Hi everyone when I run this code I am getting the value of Detected "0:2147483648" which is wrong in terminal I am getting value 0x0 which is correct why wrong in qtcreator?
                                  /@
                                  QProcess DD;
                                  DD.start("sudo devmem2 0x80000000");
                                  DD.waitForFinished(); // will wait forever until finished
                                  QString dds (DD.readAllStandardOutput());
                                  dds = dds.replace("(","").replace(")","").replace(":","");
                                  auto split = dds.split("0x");
                                  QString dds_en("%1:%2");
                                  dds_en = dds_en.arg(split.at(1).toLongLong(nullptr,16)).arg(split.at(2).toLongLong(nullptr,16));
                                  // dds_en =QString::number(split.at(1),16);
                                  qDebug()<<"Detected:"<<dds_en;

                                  @/

                                  1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    ChrisW67
                                    wrote on last edited by
                                    #18

                                    @Wasee Could you please put your code in tags so the forum treats it as code. You start or end a code block with three backticks `.

                                    Why do you think that is wrong? 2147483648 (decimal) is 0x80000000, which looks suspiciously like what you asked for.

                                    Since you still have not shared exactly what devmem2 gives you in both cases I can only guess that devmem2 is failing completely when run in the environment that Qt Creator provides. In this environment it is quite possible sudo will not function.

                                    1 Reply Last reply
                                    4
                                    • WaseeW Offline
                                      WaseeW Offline
                                      Wasee
                                      wrote on last edited by
                                      #19

                                      @ChrisW67 thanks;
                                      "sudo devmem2 0x80000000" gives value in terminal is 0x0 but in qt code its value is 2147483648 which I stated above in previous post.
                                      thanks

                                      KroMignonK 1 Reply Last reply
                                      0
                                      • WaseeW Wasee

                                        @ChrisW67 thanks;
                                        "sudo devmem2 0x80000000" gives value in terminal is 0x0 but in qt code its value is 2147483648 which I stated above in previous post.
                                        thanks

                                        KroMignonK Offline
                                        KroMignonK Offline
                                        KroMignon
                                        wrote on last edited by KroMignon
                                        #20

                                        @Wasee said in Qt program crash why?:

                                        "sudo devmem2 0x80000000" gives value in terminal is 0x0 but in qt code its value is 2147483648 which I stated above in previous post.

                                        I would try to do thing step by step.
                                        First ensure the QProcess call is working, and then try to parse result.
                                        I am not sure that the way you are using QProcess with sudo is the best way.
                                        I would do it this way:

                                        QProcess proc;
                                        QStringList args;
                                        
                                        proc.setProcessChannelMode(QProcess::MergedChannels);
                                        args << "devmem2" << "0x80000000";
                                        
                                        proc.start("sudo", args);
                                        if(proc.waitForFinished())
                                        {
                                            QString result = QString(proc.readAll());
                                            qDebug() << "devmem2 done and returning" << result;
                                        }
                                        else
                                            qDebug() << "failled to start devmem2";
                                        

                                        NOTE: to add code in your post, please use </> button, this made it easier to read

                                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                        1 Reply Last reply
                                        3
                                        • WaseeW Offline
                                          WaseeW Offline
                                          Wasee
                                          wrote on last edited by
                                          #21

                                          @KroMignon thanks for your help:
                                          I coded as you suggested my output is:
                                          devmem2 done and returning: "/dev/mem opened. Memory mapped at address 0xb6f90000. Value at address 0x80000000 (0xb6f90000): 0x0 "
                                          This is very long string I just needed value 0x0 not whole string.

                                          Thanks your help!

                                          jsulmJ KroMignonK 2 Replies 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