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 4.5k 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.
  • C Christian Ehrlicher
    3 Jan 2022, 09:01

    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 Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 3 Jan 2022, 09:13 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
    • W Wasee
      3 Jan 2022, 07:34

      @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 Online
      J Online
      JonB
      wrote on 3 Jan 2022, 09:16 last edited by JonB 1 Mar 2022, 09:22
      #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
      • W Offline
        W Offline
        Wasee
        wrote on 4 Jan 2022, 07:19 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 4 Jan 2022, 08:24 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
          • W Offline
            W Offline
            Wasee
            wrote on 4 Jan 2022, 11:24 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

            K 1 Reply Last reply 4 Jan 2022, 11:34
            0
            • W Wasee
              4 Jan 2022, 11:24

              @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

              K Offline
              K Offline
              KroMignon
              wrote on 4 Jan 2022, 11:34 last edited by KroMignon 1 Apr 2022, 11:35
              #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

              1 Reply Last reply
              3
              • W Offline
                W Offline
                Wasee
                wrote on 5 Jan 2022, 05:55 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!

                J K 2 Replies Last reply 5 Jan 2022, 06:23
                0
                • W Wasee
                  5 Jan 2022, 05:55

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

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 5 Jan 2022, 06:23 last edited by
                  #22

                  @Wasee said in Qt program crash why?:

                  This is very long string I just needed value 0x0 not whole string

                  Then simply split the string using ':' character and take the second part, see https://doc.qt.io/qt-5/qstring.html#split-5.
                  This of course assumes that there is only one ':' in the result string. If not, you will need to use split() with regular expression.

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

                  1 Reply Last reply
                  4
                  • W Wasee
                    5 Jan 2022, 05:55

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

                    K Offline
                    K Offline
                    KroMignon
                    wrote on 5 Jan 2022, 07:01 last edited by KroMignon 1 May 2022, 07:18
                    #23

                    @Wasee said in Qt program crash why?:

                    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!

                    That is only a simple string manipulation.
                    The easiest way is to search for the first occurence of 0x by starting from the end and then parse this string part.
                    Take a look a QString documentation, you should be able to find this yourself.

                    1 Reply Last reply
                    3
                    • W Offline
                      W Offline
                      Wasee
                      wrote on 5 Jan 2022, 09:22 last edited by
                      #24

                      @KroMignon Hi;
                      I added following lines in code:

                      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;
                         args = result.split(QRegExp("\\:"));
                         args.removeFirst();
                       qDebug()<<"Truncated:"<<args;
                      }
                      else
                          qDebug() << "failled to start devmem2";
                      

                      Its giving value ("0x0") I need it without bracket 0x0.
                      Thanks

                      K 1 Reply Last reply 5 Jan 2022, 09:31
                      0
                      • W Wasee
                        5 Jan 2022, 09:22

                        @KroMignon Hi;
                        I added following lines in code:

                        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;
                           args = result.split(QRegExp("\\:"));
                           args.removeFirst();
                         qDebug()<<"Truncated:"<<args;
                        }
                        else
                            qDebug() << "failled to start devmem2";
                        

                        Its giving value ("0x0") I need it without bracket 0x0.
                        Thanks

                        K Offline
                        K Offline
                        KroMignon
                        wrote on 5 Jan 2022, 09:31 last edited by
                        #25

                        @Wasee said in Qt program crash why?:

                        Its giving value ("0x0") I need it without bracket 0x0.
                        Thanks

                        Why doing so complicated?
                        Have your read QString documentation?
                        You should found QString::lastIndexOf()

                        QString result = QString(proc.readAll());
                        QString value =  result.mid(result.lastIndexOf("0x"));
                        qDebug()<<"Truncated:"<<value;
                        
                        
                        1 Reply Last reply
                        1
                        • W Offline
                          W Offline
                          Wasee
                          wrote on 7 Jan 2022, 06:50 last edited by
                          #26

                          @KroMignon Hi;
                          Truncated: "0x1
                          "
                          Why its not "0x0"? Last quotation mark is on next line.

                          K 1 Reply Last reply 7 Jan 2022, 07:09
                          0
                          • W Wasee
                            7 Jan 2022, 06:50

                            @KroMignon Hi;
                            Truncated: "0x1
                            "
                            Why its not "0x0"? Last quotation mark is on next line.

                            K Offline
                            K Offline
                            KroMignon
                            wrote on 7 Jan 2022, 07:09 last edited by KroMignon 1 Jul 2022, 07:10
                            #27

                            @Wasee said in Qt program crash why?:

                            Why its not "0x0"? Last quotation mark is on next line.

                            perhaps because the return value has changed?
                            Did you display QProcess output to compare with result?

                            QString result = QString(proc.readAll());
                            QString value =  result.mid(result.lastIndexOf("0x"));
                            qDebug()<<"Returned value:"<<result ;
                            qDebug()<<"Truncated:"<<value;
                            

                            Note: it seems that returned string contains also a carriage return byte, you could remove this by using QString::simplified() (cf. https://doc.qt.io/qt-5/qstring.html#simplified)

                            1 Reply Last reply
                            1
                            • W Offline
                              W Offline
                              Wasee
                              wrote on 7 Jan 2022, 07:20 last edited by
                              #28

                              @KroMignon Hi;

                              qDebug()<<"Returned value:"<<result ;
                              

                              Returned value:"/dev/mem opened.
                              Memory mapped at address 0xb6f90000.
                              Value at address 0x80000000 (0xb6f90000): 0x1
                              "

                              thanks

                              1 Reply Last reply
                              0
                              • W Offline
                                W Offline
                                Wasee
                                wrote on 7 Jan 2022, 10:41 last edited by
                                #29

                                Hi everyone;
                                I code following and getting ASSERT: "count > 0" error. The program has unexpectedly finished. Why?

                                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;
                                    QString dds_en = result.mid(result.lastIndexOf("0x"));
                                    QString test=dds_en.simplified();
                                    qDebug()<<"Detected:"<<dds_en;
                                    if(test="0x0"){
                                    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();
                                                     qDebug() << "RX LO"<<Rx_CF_read;
                                }
                                                 if(test="0x1"){
                                                 ac=Rx_CF_read;
                                                  QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
                                                  if (f.open(QIODevice::WriteOnly))
                                                  {
                                                      qint64 count = f.write(ac.toUtf8());
                                                      Q_ASSERT(count > 0);
                                                      f.close();
                                                     qDebug()<<"QFile Run"<<count;
                                                  }
                                }
                                
                                }
                                else
                                    qDebug() << "failled to start devmem2";
                                

                                Thanks

                                K J 2 Replies Last reply 7 Jan 2022, 10:52
                                0
                                • W Wasee
                                  7 Jan 2022, 10:41

                                  Hi everyone;
                                  I code following and getting ASSERT: "count > 0" error. The program has unexpectedly finished. Why?

                                  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;
                                      QString dds_en = result.mid(result.lastIndexOf("0x"));
                                      QString test=dds_en.simplified();
                                      qDebug()<<"Detected:"<<dds_en;
                                      if(test="0x0"){
                                      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();
                                                       qDebug() << "RX LO"<<Rx_CF_read;
                                  }
                                                   if(test="0x1"){
                                                   ac=Rx_CF_read;
                                                    QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
                                                    if (f.open(QIODevice::WriteOnly))
                                                    {
                                                        qint64 count = f.write(ac.toUtf8());
                                                        Q_ASSERT(count > 0);
                                                        f.close();
                                                       qDebug()<<"QFile Run"<<count;
                                                    }
                                  }
                                  
                                  }
                                  else
                                      qDebug() << "failled to start devmem2";
                                  

                                  Thanks

                                  K Offline
                                  K Offline
                                  KroMignon
                                  wrote on 7 Jan 2022, 10:52 last edited by
                                  #30
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • W Offline
                                    W Offline
                                    Wasee
                                    wrote on 7 Jan 2022, 10:56 last edited by
                                    #31

                                    @KroMignon Hi;
                                    Rx_CF_read and ac are define in header file as QString. Rx_CF_read is RX LO value which is reading from device continuously.
                                    Thanks

                                    K 1 Reply Last reply 7 Jan 2022, 10:59
                                    0
                                    • W Wasee
                                      7 Jan 2022, 10:41

                                      Hi everyone;
                                      I code following and getting ASSERT: "count > 0" error. The program has unexpectedly finished. Why?

                                      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;
                                          QString dds_en = result.mid(result.lastIndexOf("0x"));
                                          QString test=dds_en.simplified();
                                          qDebug()<<"Detected:"<<dds_en;
                                          if(test="0x0"){
                                          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();
                                                           qDebug() << "RX LO"<<Rx_CF_read;
                                      }
                                                       if(test="0x1"){
                                                       ac=Rx_CF_read;
                                                        QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
                                                        if (f.open(QIODevice::WriteOnly))
                                                        {
                                                            qint64 count = f.write(ac.toUtf8());
                                                            Q_ASSERT(count > 0);
                                                            f.close();
                                                           qDebug()<<"QFile Run"<<count;
                                                        }
                                      }
                                      
                                      }
                                      else
                                          qDebug() << "failled to start devmem2";
                                      

                                      Thanks

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 7 Jan 2022, 10:59 last edited by
                                      #32

                                      @Wasee said in Qt program crash why?:

                                      Why?

                                      Ask https://doc.qt.io/qt-5/qfiledevice.html#error

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

                                      1 Reply Last reply
                                      0
                                      • W Wasee
                                        7 Jan 2022, 10:56

                                        @KroMignon Hi;
                                        Rx_CF_read and ac are define in header file as QString. Rx_CF_read is RX LO value which is reading from device continuously.
                                        Thanks

                                        K Offline
                                        K Offline
                                        KroMignon
                                        wrote on 7 Jan 2022, 10:59 last edited by KroMignon 1 Jul 2022, 11:02
                                        #33

                                        @Wasee said in Qt program crash why?:

                                        Rx_CF_read and ac are define in header file as QString. Rx_CF_read is RX LO value which is reading from device continuously.
                                        Thanks

                                        @Wasee

                                        Are you sure Rx_CF_read contains a valid value?
                                        Why are you using an extra copy to ac?
                                        Are you are writing into a linux virtual file, I don't think it supports UTF-8, but should be latin1.

                                        I would change to code as follow, to understand what's happening:

                                            if(test=="0x1"){
                                                QFile f("/sys/bus/iio/devices/iio:device1/out_altvoltage1_TX_LO_frequency");
                                                qDebug() << "Try to set out_altvoltage1_TX_LO_frequency to" << Rx_CF_read;
                                                if (f.open(QIODevice::WriteOnly))
                                                {
                                                    qint64 count = f.write(Rx_CF_read.toLatin1());
                                                    Q_ASSERT(count > 0);
                                                    f.close();
                                                    qDebug()<<"QFile Run"<<count;
                                                }
                                            }
                                        

                                        EDIT ==> = is to set a value, to compare use ==!!!!
                                        if(test="0x0") ==> if(test=="0x0")
                                        if(test="0x1") ==> if(test=="0x1")

                                        1 Reply Last reply
                                        1
                                        • W Offline
                                          W Offline
                                          Wasee
                                          wrote on 7 Jan 2022, 11:12 last edited by
                                          #34

                                          @KroMignon Hi;
                                          I change the code but getting ASSERT: "count > 0" error. The program has unexpectedly finished.

                                          Try to set out_altvoltage1_TX_LO_frequency to ""
                                          Thanks

                                          K 1 Reply Last reply 7 Jan 2022, 11:40
                                          0

                                          24/38

                                          5 Jan 2022, 09:22

                                          • Login

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