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. QtConcurrentRun calls non-qt function
Forum Update on Monday, May 27th 2025

QtConcurrentRun calls non-qt function

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 2.4k Views
  • 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.
  • S Offline
    S Offline
    sharethl
    wrote on 23 Feb 2015, 17:05 last edited by
    #1

    Hi,

    When QtConcurrentRun calls a non-qt function (c++ oop library), it has a chance to crash.
    Tested multiple times under exactly same conditions.

    Is this a known problem?
    Or it is simply my non-qt function has bug?

    Thanks.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Feb 2015, 17:13 last edited by
      #2

      Hi,

      QtConcurrentRun doesn't need your function to be Qt specific. Can you share the code of that function ?

      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
      • S Offline
        S Offline
        sharethl
        wrote on 23 Feb 2015, 18:01 last edited by
        #3

        [quote author="SGaist" date="1424711613"]Hi,

        QtConcurrentRun doesn't need your function to be Qt specific. Can you share the code of that function ?[/quote]

        Here is QtConcurrentRun function.
        _brc is an object in non-qt library.
        Usually crash(show disassembler view) after line 5.

        @void Spectrometer::doScanning()
        {
        if(_isFunctional==false) return; // disable operation if not functional

        int result = _brc->startAcquiring();
        
        //emit dataAcquisitionFinished(); // tell manager this data has been acquired.
        
        quint16 dataBuffer[SpectrometerData::PIXEL_NUM];
        if(result == 1){
            result = _brc->getYData(dataBuffer);
        }
        else{
            // TODO:add error message box
            return;
        }
        
        _data_ptr.data()->updateUid(); // make new id to avoid duplication.
        
        //for flipped Spectrometer
        for(int i=0;i<SpectrometerData::PIXEL_NUM;i++){
            auto y = dataBuffer[SpectrometerData::PIXEL_NUM-i-1];
            _data_ptr.data()->updateY(i,y);
        }
        
        _isWorking=false;
        qDebug() << "Scan Finished";
        emit scanFinished();
        

        }@

        @bool BRC::startAcquiring(){
        char cmd[]="E\r\n";
        int cmdLength = strlen(cmd);
        if (write(_fd, cmd, cmdLength) < cmdLength){
        return false;
        }
        return (wait("DR",cmdLength+7, _timeout));
        }@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Feb 2015, 21:43 last edited by
          #4

          You are trying to write on the same file descriptor from several thread at once ?

          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
          • S Offline
            S Offline
            sharethl
            wrote on 23 Feb 2015, 23:05 last edited by
            #5

            [quote author="SGaist" date="1424727828"]You are trying to write on the same file descriptor from several thread at once ?[/quote]

            No, BRC is a class, and each BRC object has its own file descriptor.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 23 Feb 2015, 23:24 last edited by
              #6

              Can you also show your call to QtConcurrentRun ?

              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
              • S Offline
                S Offline
                sharethl
                wrote on 23 Feb 2015, 23:28 last edited by
                #7

                Device manager contains two spectrometers,

                @bool DeviceManager::scan()
                {
                _meter0->scan(); // scan in parallel
                _meter1->scan(); // scan in parallel
                return true;
                }@
                @bool Spectrometer::scan()
                {
                _progress = 0;
                emit reportProgress(_progress);
                // this will run parallel
                QtConcurrent::run(this,&Spectrometer::doScanning);
                _isWorking=true;
                return true;
                }@

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Feb 2015, 00:47 last edited by
                  #8

                  Then are you sure that _brc is properly allocated ? That both are no trying to access the same resources at the same time ?

                  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
                  • S Offline
                    S Offline
                    sharethl
                    wrote on 24 Feb 2015, 01:51 last edited by
                    #9

                    _brc is a pointer in Spectrometer class.
                    and I use new BRC() in Spectrometer's constructor.
                    Works most of time.

                    and during my app starts up, each _brc did communicate with their corresponding hardware successfully.

                    Is it possible to allocate differently with same code but different runs?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 25 Feb 2015, 20:42 last edited by
                      #10

                      What does the backtrace of a crash tell you ?

                      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
                      • S Offline
                        S Offline
                        sharethl
                        wrote on 26 Feb 2015, 00:10 last edited by
                        #11

                        you mean stack trace?

                        two lines of ??

                        [quote author="SGaist" date="1424896978"]What does the backtrace of a crash tell you ?[/quote]

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 26 Feb 2015, 23:36 last edited by
                          #12

                          Are you running a debug build ?

                          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
                          • S Offline
                            S Offline
                            sharethl
                            wrote on 27 Feb 2015, 00:20 last edited by
                            #13

                            [quote author="SGaist" date="1424993803"]Are you running a debug build ?
                            [/quote]

                            Yes

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 27 Feb 2015, 23:56 last edited by
                              #14

                              Ok, then what does the debugger tell you ?

                              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

                              1/14

                              23 Feb 2015, 17:05

                              • Login

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