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.
  • 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
    • WaseeW Wasee

      @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 Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      • WaseeW Wasee

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

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #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
        • WaseeW Offline
          WaseeW Offline
          Wasee
          wrote on 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

          KroMignonK 1 Reply Last reply
          0
          • WaseeW Wasee

            @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

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on 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
            • WaseeW Offline
              WaseeW Offline
              Wasee
              wrote on last edited by
              #26

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

              KroMignonK 1 Reply Last reply
              0
              • WaseeW Wasee

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

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by KroMignon
                #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
                • WaseeW Offline
                  WaseeW Offline
                  Wasee
                  wrote on 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
                  • WaseeW Offline
                    WaseeW Offline
                    Wasee
                    wrote on 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

                    KroMignonK jsulmJ 2 Replies Last reply
                    0
                    • WaseeW Wasee

                      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

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #30
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • WaseeW Offline
                        WaseeW Offline
                        Wasee
                        wrote on 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

                        KroMignonK 1 Reply Last reply
                        0
                        • WaseeW Wasee

                          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

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 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
                          • WaseeW Wasee

                            @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

                            KroMignonK Offline
                            KroMignonK Offline
                            KroMignon
                            wrote on last edited by KroMignon
                            #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
                            • WaseeW Offline
                              WaseeW Offline
                              Wasee
                              wrote on 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

                              KroMignonK 1 Reply Last reply
                              0
                              • WaseeW Wasee

                                @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

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

                                @Wasee said in Qt program crash why?:

                                Try to set out_altvoltage1_TX_LO_frequency to ""

                                According to the debug message, you are writing an empty string.
                                So why should count be greater than 0?

                                Have you also change the if statements?
                                if(test="0x1") will change test to "0x1" and not compare test with string "0x1"

                                In C/C++ the comparison operator is ==

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

                                  @KroMignon Hi;
                                  If statement is working for if(test=="0x0") but not for if(test=="0x1"). Even test value in terminal is "0x1". at this point not entertaining to this if condition.
                                  thanks

                                  JonBJ KroMignonK 2 Replies Last reply
                                  0
                                  • WaseeW Wasee

                                    @KroMignon Hi;
                                    If statement is working for if(test=="0x0") but not for if(test=="0x1"). Even test value in terminal is "0x1". at this point not entertaining to this if condition.
                                    thanks

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

                                    @Wasee
                                    You really need to use a debugger, or even just debug statements, to find out for yourself things like what is in a variable, how should asking here help, other people don't know whether you get 0x0 versus 0x1 or whatever back, you are best placed to discover that....

                                    1 Reply Last reply
                                    0
                                    • WaseeW Wasee

                                      @KroMignon Hi;
                                      If statement is working for if(test=="0x0") but not for if(test=="0x1"). Even test value in terminal is "0x1". at this point not entertaining to this if condition.
                                      thanks

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

                                      @Wasee said in Qt program crash why?:

                                      If statement is working for if(test=="0x0") but not for if(test=="0x1"). Even test value in terminal is "0x1". at this point not entertaining to this if condition.
                                      thanks

                                      I don't want to hurt you, but it looks like you are not really understanding what you are doing.
                                      Why you don't use the debugger to set break points and running this part of code step by step to see what is really happening, as @JonB suggest to you?

                                      1 Reply Last reply
                                      1

                                      • Login

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