Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QList<const QBluetoothDeviceInfo* declaration / definiton problem
Forum Updated to NodeBB v4.3 + New Features

QList<const QBluetoothDeviceInfo* declaration / definiton problem

Scheduled Pinned Locked Moved Unsolved C++ Gurus
47 Posts 6 Posters 23.0k Views 4 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.
  • Axel SpoerlA Axel Spoerl

    @AnneRanch
    If you want free advice here, please take the time and effort to format your code nicely.
    You can safely assume that container classes work correctly. So probably your “other method” queries it at a point where it is still empty or empty again. Since you don’t show the code where you populate the list, it’s hard to say why it is empty when you expect the opposite.

    A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by Anonymous_Banned275
    #3

    @Axel-Spoerl OK, I did say I copied
    the text from text editor

    ( copied from text editor , hence NO code formatting )

    • which should be understood that it could not be formatted to your liking using forum software.

    If it bothers you to give free advise because I did not formatted the code correctly

    • my advise to you is - do not reply at all .

    Your opinion is non productive , it does not help me to solve the problem.

    Even if code is not formatted to your liking you should be able to determine that the issue is NOT in "filling the variable ".
    I specifically included code which I said works as expected and code which verifies the contents of the variable.
    Apparently you either did not bother to read it or have no understanding of the code .
    If you not get the code - why don't you ask for explanation ?
    Let's get back to resolving the issue and stop bickering about formalities.
    Cheers

    PS The forum editor replaces dash with dot it knows Morse code....

    Axel SpoerlA 1 Reply Last reply
    0
    • A Anonymous_Banned275

      @Axel-Spoerl OK, I did say I copied
      the text from text editor

      ( copied from text editor , hence NO code formatting )

      • which should be understood that it could not be formatted to your liking using forum software.

      If it bothers you to give free advise because I did not formatted the code correctly

      • my advise to you is - do not reply at all .

      Your opinion is non productive , it does not help me to solve the problem.

      Even if code is not formatted to your liking you should be able to determine that the issue is NOT in "filling the variable ".
      I specifically included code which I said works as expected and code which verifies the contents of the variable.
      Apparently you either did not bother to read it or have no understanding of the code .
      If you not get the code - why don't you ask for explanation ?
      Let's get back to resolving the issue and stop bickering about formalities.
      Cheers

      PS The forum editor replaces dash with dot it knows Morse code....

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #4

      @AnneRanch
      Thanks for your advice not to reply, and for the hint that my opinion is non productive. Also thanks for the encouragement to crawl my way through unformatted code. I wish you a perfect solution to the issue. Keep smiling!

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      8
      • Axel SpoerlA Axel Spoerl

        @AnneRanch
        If you want free advice here, please take the time and effort to format your code nicely.
        You can safely assume that container classes work correctly. So probably your “other method” queries it at a point where it is still empty or empty again. Since you don’t show the code where you populate the list, it’s hard to say why it is empty when you expect the opposite.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by Anonymous_Banned275
        #5

        @Axel-Spoerl Many thanks for the reply. I do appreciate it. Here is my view and some missing explanation from original post .
        The container is filed , copied from another variable, when the class is constructed and the code posted works as expected.
        The other method , in same class . is run AFTER GUI " button" is clicked - hence manually and well after the class is constructed. Its current , starting task , is just to certify the contents of the container.
        That is what is failing.
        I just do not understand why the same code of test verifying range loop works in one function / method and fails in another.
        Obviously I am missing something and I do not know what.
        The container if defined as a variable in the "public" area of the class , perhaps the definition is wrong. I just do not know.
        Thanks for taking your time to discuss this issue.

        Axel SpoerlA 1 Reply Last reply
        0
        • A Anonymous_Banned275

          @Axel-Spoerl Many thanks for the reply. I do appreciate it. Here is my view and some missing explanation from original post .
          The container is filed , copied from another variable, when the class is constructed and the code posted works as expected.
          The other method , in same class . is run AFTER GUI " button" is clicked - hence manually and well after the class is constructed. Its current , starting task , is just to certify the contents of the container.
          That is what is failing.
          I just do not understand why the same code of test verifying range loop works in one function / method and fails in another.
          Obviously I am missing something and I do not know what.
          The container if defined as a variable in the "public" area of the class , perhaps the definition is wrong. I just do not know.
          Thanks for taking your time to discuss this issue.

          Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #6

          @AnneRanch
          Please don't take it offensive: Nobody, including me, will have fun reading code, if it is not formatted.
          I haven't read it and I won't read it the way it is posted.
          It's possible to format it, it just takes a bit patience and time.
          Start the code block with 3 times ` and end it the same way.
          Don't stop, before the code looks nice in the preview window on your right.
          Please also post the entire code, not just fragments.
          If you want anybody here to dig into an issue: That's your ticket.

          For the records: If you feel like insulting me (again) for claiming formatted code: Swallow it from now on.

          Software Engineer
          The Qt Company, Oslo

          A 1 Reply Last reply
          3
          • Axel SpoerlA Axel Spoerl

            @AnneRanch
            Please don't take it offensive: Nobody, including me, will have fun reading code, if it is not formatted.
            I haven't read it and I won't read it the way it is posted.
            It's possible to format it, it just takes a bit patience and time.
            Start the code block with 3 times ` and end it the same way.
            Don't stop, before the code looks nice in the preview window on your right.
            Please also post the entire code, not just fragments.
            If you want anybody here to dig into an issue: That's your ticket.

            For the records: If you feel like insulting me (again) for claiming formatted code: Swallow it from now on.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by Anonymous_Banned275
            #7

            @Axel-Spoerl OK, here is my unbiased opinion . I have described the problem and I firmly believe it is not a coding issue.
            There is something wrong with the way the container is defined or used. However , it it helps to find a solution I can re post reformatted code.
            Please keep in mind it is a code under construction,

                Q_OBJECT
            
            public:
                // add May 14
                void on_applyButton_10_clicked();
                //making a list May 13
                QList<const QBluetoothDeviceInfo* > RemoteDeviceInfo;
            
            
            

            This copies data from info into RemoteDeviceInfo and works as expected

            {
                        text = "\n TASK addDevice ";
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
                        m_ui->plainTextEdit_3->appendPlainText(text);
                        text = " device address ";
                        text += info.address().toString();
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
                        m_ui->plainTextEdit_3->appendPlainText(text);
            
                        text = " device name ";
                        text += info.name();
                        text += "\n";
            
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
                        m_ui->plainTextEdit_3->appendPlainText(text);
            
                        text = " TASK pair device name ";
                        text += info.name();
                        text += "\n";
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
                        //return;
            
                        // QBluetoothLocalDevice::Pairing
                        int pairingStatus = localDevice->pairingStatus(info.address());
                        text = " TASK pairingStatus ";
                        text += info.name();
                        text += QString::number(pairingStatus);
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
            
            
                        //QList devicesList info
                        RemoteDeviceInfo = new QBluetoothHostInfo();
                        //TestClass* test_1 = new TestClass(&a);
                        //test_list.append(test_1);
            
                        RemoteDeviceInfo.append(&info);
            
                        // verify
                        text = "!!!!!!!!!   DEBUG verify RemoteDeviceInfo \n";
                        text += " name \n";
                        text += RemoteDeviceInfo.at(0)->name();
                        qDebug() << text;
                        m_ui->plainTextEdit_8->appendPlainText(text);
                        // m_ui->plainTextEdit_3->appendPlainText(text);
            
                        for(auto &device:RemoteDeviceInfo)
                        {
                            text = " BUILD  range loop test ";
                            m_ui->plainTextEdit_8->appendPlainText(text);
            
                            text = " device name ";
                            text += device->name();
                            m_ui->plainTextEdit_8->appendPlainText(text);
                        }
            
            
            
            
            
            
            
            
            
            
            
            
                        //return;
            
                        text = " TASK pairingStatus ";
                        text += info.name();
                        text += QString::number(pairingStatus);  // this is usibg last localDevice->pairingStatus(info.address());
                        if (pairingStatus == QBluetoothLocalDevice::Paired || pairingStatus == QBluetoothLocalDevice::AuthorizedPaired )
                        {
                            text += " PAIRED ";
                            //item->setForeground(QColor(Qt::green));
                        }
                        else
                        {
                            text += " NOT PAIRED ";
            
                            //item->setForeground(QColor(Qt::black));
            
                        }
            
                        //return;
            
                        qDebug()<< text;
                        m_ui->plainTextEdit->appendPlainText(text);
            
            
                        // request pairing
            
                        if( pairingStatus == 0 )
                        {
                            text = " TASK request pairing ";
                            text += info.name();
                            qDebug()<< text;
                            m_ui->plainTextEdit->appendPlainText(text);
            
                            localDevice->requestPairing(info.address(),QBluetoothLocalDevice::Pairing());
            
            
                            text = " TASK continue ";
                            qDebug()<< text;
                            m_ui->plainTextEdit->appendPlainText(text);
            
                        }
            
            
            
            
            
            
            
            
            
            #ifdef BYPASS
            
            
                        QString label = QString("%1 %2").arg(info.address().toString()).arg(info.name());
                        //    QList<QListWidgetItem *> items = ui->list->findItems(label, Qt::MatchExactly);
                        if (items.empty()) {
                            QListWidgetItem *item = new QListWidgetItem(label);
                            QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(info.address());
                            if (pairingStatus == QBluetoothLocalDevice::Paired || pairingStatus == QBluetoothLocalDevice::AuthorizedPaired )
                                item->setForeground(QColor(Qt::green));
                            else
                                item->setForeground(QColor(Qt::black));
            
                            //       ui->list->addItem(item);
            #endif
                        }
            
            This s code attempts to verify the contents of RemoteDeviceInfo and fails to  do so.
            
            
                                void SettingsDialog::on_applyButton_11_clicked()
                                {
                                    text = "Test range loop \n";
                                    text += Q_FUNC_INFO;
                                    qDebug()<< text;
                                    m_ui->plainTextEdit_8->appendPlainText(text);
                                    if(!RemoteDeviceInfo.isEmpty())
                                    {
                                        for (auto &device:RemoteDeviceInfo)
                                        {
                                            text = " For loop test ";
                                            qDebug() << text;
                                            text = " device address \n";
                                            text += device->address().toString();
                                            qDebug() << text;
                                            m_ui->plainTextEdit_8->appendPlainText(text);
                                            text = " device name  \n";
                                            text += device->name(); // >address().toString()
                                            qDebug() << text;
                                            m_ui->plainTextEdit_8->appendPlainText(text);
            
            
                                        }
                                    }
                                }
            

            I will be more than happy to provide additional information to help solve this if requested

            I have added class variable TEST and set it when RemoteDeviceInfo is build. I have also added debug text to the function verifying the content of RemoteDeviceInfo and it can be seen in attached run output as set to 1.

            qt.bluetooth.bluez: Device discovery aborted due to unexpected adapter changes from another process.
            "Test range loop \nvoid SettingsDialog::on_applyButton_11_clicked() !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TEST !!!!!!!!!!!!1"
            " For loop test "
            11:04:07: /mnt/RAID_124/PROJECTS_May14_BASE_/mdi/MDI crashed.

            Christian EhrlicherC 1 Reply Last reply
            0
            • A Anonymous_Banned275

              @Axel-Spoerl OK, here is my unbiased opinion . I have described the problem and I firmly believe it is not a coding issue.
              There is something wrong with the way the container is defined or used. However , it it helps to find a solution I can re post reformatted code.
              Please keep in mind it is a code under construction,

                  Q_OBJECT
              
              public:
                  // add May 14
                  void on_applyButton_10_clicked();
                  //making a list May 13
                  QList<const QBluetoothDeviceInfo* > RemoteDeviceInfo;
              
              
              

              This copies data from info into RemoteDeviceInfo and works as expected

              {
                          text = "\n TASK addDevice ";
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
                          m_ui->plainTextEdit_3->appendPlainText(text);
                          text = " device address ";
                          text += info.address().toString();
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
                          m_ui->plainTextEdit_3->appendPlainText(text);
              
                          text = " device name ";
                          text += info.name();
                          text += "\n";
              
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
                          m_ui->plainTextEdit_3->appendPlainText(text);
              
                          text = " TASK pair device name ";
                          text += info.name();
                          text += "\n";
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
                          //return;
              
                          // QBluetoothLocalDevice::Pairing
                          int pairingStatus = localDevice->pairingStatus(info.address());
                          text = " TASK pairingStatus ";
                          text += info.name();
                          text += QString::number(pairingStatus);
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
              
              
                          //QList devicesList info
                          RemoteDeviceInfo = new QBluetoothHostInfo();
                          //TestClass* test_1 = new TestClass(&a);
                          //test_list.append(test_1);
              
                          RemoteDeviceInfo.append(&info);
              
                          // verify
                          text = "!!!!!!!!!   DEBUG verify RemoteDeviceInfo \n";
                          text += " name \n";
                          text += RemoteDeviceInfo.at(0)->name();
                          qDebug() << text;
                          m_ui->plainTextEdit_8->appendPlainText(text);
                          // m_ui->plainTextEdit_3->appendPlainText(text);
              
                          for(auto &device:RemoteDeviceInfo)
                          {
                              text = " BUILD  range loop test ";
                              m_ui->plainTextEdit_8->appendPlainText(text);
              
                              text = " device name ";
                              text += device->name();
                              m_ui->plainTextEdit_8->appendPlainText(text);
                          }
              
              
              
              
              
              
              
              
              
              
              
              
                          //return;
              
                          text = " TASK pairingStatus ";
                          text += info.name();
                          text += QString::number(pairingStatus);  // this is usibg last localDevice->pairingStatus(info.address());
                          if (pairingStatus == QBluetoothLocalDevice::Paired || pairingStatus == QBluetoothLocalDevice::AuthorizedPaired )
                          {
                              text += " PAIRED ";
                              //item->setForeground(QColor(Qt::green));
                          }
                          else
                          {
                              text += " NOT PAIRED ";
              
                              //item->setForeground(QColor(Qt::black));
              
                          }
              
                          //return;
              
                          qDebug()<< text;
                          m_ui->plainTextEdit->appendPlainText(text);
              
              
                          // request pairing
              
                          if( pairingStatus == 0 )
                          {
                              text = " TASK request pairing ";
                              text += info.name();
                              qDebug()<< text;
                              m_ui->plainTextEdit->appendPlainText(text);
              
                              localDevice->requestPairing(info.address(),QBluetoothLocalDevice::Pairing());
              
              
                              text = " TASK continue ";
                              qDebug()<< text;
                              m_ui->plainTextEdit->appendPlainText(text);
              
                          }
              
              
              
              
              
              
              
              
              
              #ifdef BYPASS
              
              
                          QString label = QString("%1 %2").arg(info.address().toString()).arg(info.name());
                          //    QList<QListWidgetItem *> items = ui->list->findItems(label, Qt::MatchExactly);
                          if (items.empty()) {
                              QListWidgetItem *item = new QListWidgetItem(label);
                              QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(info.address());
                              if (pairingStatus == QBluetoothLocalDevice::Paired || pairingStatus == QBluetoothLocalDevice::AuthorizedPaired )
                                  item->setForeground(QColor(Qt::green));
                              else
                                  item->setForeground(QColor(Qt::black));
              
                              //       ui->list->addItem(item);
              #endif
                          }
              
              This s code attempts to verify the contents of RemoteDeviceInfo and fails to  do so.
              
              
                                  void SettingsDialog::on_applyButton_11_clicked()
                                  {
                                      text = "Test range loop \n";
                                      text += Q_FUNC_INFO;
                                      qDebug()<< text;
                                      m_ui->plainTextEdit_8->appendPlainText(text);
                                      if(!RemoteDeviceInfo.isEmpty())
                                      {
                                          for (auto &device:RemoteDeviceInfo)
                                          {
                                              text = " For loop test ";
                                              qDebug() << text;
                                              text = " device address \n";
                                              text += device->address().toString();
                                              qDebug() << text;
                                              m_ui->plainTextEdit_8->appendPlainText(text);
                                              text = " device name  \n";
                                              text += device->name(); // >address().toString()
                                              qDebug() << text;
                                              m_ui->plainTextEdit_8->appendPlainText(text);
              
              
                                          }
                                      }
                                  }
              

              I will be more than happy to provide additional information to help solve this if requested

              I have added class variable TEST and set it when RemoteDeviceInfo is build. I have also added debug text to the function verifying the content of RemoteDeviceInfo and it can be seen in attached run output as set to 1.

              qt.bluetooth.bluez: Device discovery aborted due to unexpected adapter changes from another process.
              "Test range loop \nvoid SettingsDialog::on_applyButton_11_clicked() !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TEST !!!!!!!!!!!!1"
              " For loop test "
              11:04:07: /mnt/RAID_124/PROJECTS_May14_BASE_/mdi/MDI crashed.

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

              @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                      RemoteDeviceInfo = new QBluetoothHostInfo();
              
                      RemoteDeviceInfo.append(&info);
              

              This does not even compile and even if it would - storing an adress to a local variable will result in a crash afterwards.

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

              Axel SpoerlA 1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                        RemoteDeviceInfo = new QBluetoothHostInfo();
                
                        RemoteDeviceInfo.append(&info);
                

                This does not even compile and even if it would - storing an adress to a local variable will result in a crash afterwards.

                Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #9

                Adding to @Christian-Ehrlicher:

                RemoteDeviceInfo = new QBluetoothHostInfo();

                assigns pointer to a heap allocated BluetoothHostInfo to a member variable, defined as a QList<const QBluetoothDeviceInfo* >. Whatever has been in the list up to then, will be discarded. If the code gets compiled somehow (on my machine, it doesn't), the list now contains one single, default-constructed element.

                RemoteDeviceInfo.append(&info);

                This appends the pointer to a (probably) stack allocated QBluetoothHostInfo object. Now the list will contain two pointers. One to the new default-constructed element, and another one pointing to the object that has been passed to the function as an argument. As soon as the argument-passed object goes out of scope, the list contains a pointer to a stale object.

                Next time the function is called, the list is initialized with another new default-constructed object. The previous one will leak.

                I hope that brings you closer to the problem.

                Software Engineer
                The Qt Company, Oslo

                JonBJ A 2 Replies Last reply
                0
                • Axel SpoerlA Axel Spoerl

                  Adding to @Christian-Ehrlicher:

                  RemoteDeviceInfo = new QBluetoothHostInfo();

                  assigns pointer to a heap allocated BluetoothHostInfo to a member variable, defined as a QList<const QBluetoothDeviceInfo* >. Whatever has been in the list up to then, will be discarded. If the code gets compiled somehow (on my machine, it doesn't), the list now contains one single, default-constructed element.

                  RemoteDeviceInfo.append(&info);

                  This appends the pointer to a (probably) stack allocated QBluetoothHostInfo object. Now the list will contain two pointers. One to the new default-constructed element, and another one pointing to the object that has been passed to the function as an argument. As soon as the argument-passed object goes out of scope, the list contains a pointer to a stale object.

                  Next time the function is called, the list is initialized with another new default-constructed object. The previous one will leak.

                  I hope that brings you closer to the problem.

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

                  @Axel-Spoerl said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                  If the code gets compiled somehow (on my machine, it doesn't),

                  It won't compile as shown and as @Christian-Ehrlicher said. The member variable is

                  QList<const QBluetoothDeviceInfo* > RemoteDeviceInfo;
                  

                  You can't go RemoteDeviceInfo = new anything 'coz it's not a pointer :)

                  I suspect whatever the real code there the RemoteDeviceInfo.append(&info); statement is storing pointers to local variable in the list, later on in other function they point to undefined.

                  A 1 Reply Last reply
                  1
                  • Axel SpoerlA Axel Spoerl

                    Adding to @Christian-Ehrlicher:

                    RemoteDeviceInfo = new QBluetoothHostInfo();

                    assigns pointer to a heap allocated BluetoothHostInfo to a member variable, defined as a QList<const QBluetoothDeviceInfo* >. Whatever has been in the list up to then, will be discarded. If the code gets compiled somehow (on my machine, it doesn't), the list now contains one single, default-constructed element.

                    RemoteDeviceInfo.append(&info);

                    This appends the pointer to a (probably) stack allocated QBluetoothHostInfo object. Now the list will contain two pointers. One to the new default-constructed element, and another one pointing to the object that has been passed to the function as an argument. As soon as the argument-passed object goes out of scope, the list contains a pointer to a stale object.

                    Next time the function is called, the list is initialized with another new default-constructed object. The previous one will leak.

                    I hope that brings you closer to the problem.

                    A Offline
                    A Offline
                    Anonymous_Banned275
                    wrote on last edited by
                    #11

                    @Axel-Spoerl I am very sorry , but the code I posted DOES HAVE AN ERROR and it won't compile.
                    I accidentally just posted the version which does not have the offending code of code commented out.
                    As a said my code works AKA it does compile , but fails to retrieve the contents of the container.

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Axel-Spoerl said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                      If the code gets compiled somehow (on my machine, it doesn't),

                      It won't compile as shown and as @Christian-Ehrlicher said. The member variable is

                      QList<const QBluetoothDeviceInfo* > RemoteDeviceInfo;
                      

                      You can't go RemoteDeviceInfo = new anything 'coz it's not a pointer :)

                      I suspect whatever the real code there the RemoteDeviceInfo.append(&info); statement is storing pointers to local variable in the list, later on in other function they point to undefined.

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #12

                      @JonB said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                      RemoteDeviceInfo.append(&info); statement is storing pointers to local variable in the list

                      ...and that looks as the core of the problem , but why ?

                      It is declared as class "common" variable....

                      JonBJ 1 Reply Last reply
                      0
                      • A Anonymous_Banned275

                        @JonB said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                        RemoteDeviceInfo.append(&info); statement is storing pointers to local variable in the list

                        ...and that looks as the core of the problem , but why ?

                        It is declared as class "common" variable....

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

                        @AnneRanch
                        WHAT "is declared as class "common" variable...."?

                        If you mean the RemoteDeviceInfo, yes, but that is not the problem here.

                        The problem is your statement RemoteDeviceInfo.append(&info);. Where is that info actually declared? The code you have posted won't compile that line for the info, not just the new earlier.

                        Should we guess the line

                        //QList devicesList info
                        

                        is not actually commented out? There is no other declaration for info you show. In that case it would explain the bad behaviour. But we don't know because you won't paste whatever code you use which actually compiles! We accept you have code which does compile so you get your result, but until you show that actual code it's guesswork.

                        You show a block

                                    //QList devicesList info
                                    RemoteDeviceInfo = new QBluetoothHostInfo();
                                    //TestClass* test_1 = new TestClass(&a);
                                    //test_list.append(test_1);
                        
                                    RemoteDeviceInfo.append(&info);
                        

                        What does that really look like, copied & pasted, when it compiles and gives you the bad behaviour? Does it actually read:

                                    QList devicesList info;
                                    //RemoteDeviceInfo = new QBluetoothHostInfo();
                                    //TestClass* test_1 = new TestClass(&a);
                                    //test_list.append(test_1);
                        
                                    RemoteDeviceInfo.append(&info);
                        
                        A 1 Reply Last reply
                        2
                        • JonBJ JonB

                          @AnneRanch
                          WHAT "is declared as class "common" variable...."?

                          If you mean the RemoteDeviceInfo, yes, but that is not the problem here.

                          The problem is your statement RemoteDeviceInfo.append(&info);. Where is that info actually declared? The code you have posted won't compile that line for the info, not just the new earlier.

                          Should we guess the line

                          //QList devicesList info
                          

                          is not actually commented out? There is no other declaration for info you show. In that case it would explain the bad behaviour. But we don't know because you won't paste whatever code you use which actually compiles! We accept you have code which does compile so you get your result, but until you show that actual code it's guesswork.

                          You show a block

                                      //QList devicesList info
                                      RemoteDeviceInfo = new QBluetoothHostInfo();
                                      //TestClass* test_1 = new TestClass(&a);
                                      //test_list.append(test_1);
                          
                                      RemoteDeviceInfo.append(&info);
                          

                          What does that really look like, copied & pasted, when it compiles and gives you the bad behaviour? Does it actually read:

                                      QList devicesList info;
                                      //RemoteDeviceInfo = new QBluetoothHostInfo();
                                      //TestClass* test_1 = new TestClass(&a);
                                      //test_list.append(test_1);
                          
                                      RemoteDeviceInfo.append(&info);
                          
                          A Offline
                          A Offline
                          Anonymous_Banned275
                          wrote on last edited by
                          #14

                          @JonB ok , AS I said I have accidentally posted wrong copy of the code.
                          With that removed it compiles and when I add to the new container the data shows up in the verifying loop ( as I said before ),
                          there is nothing wrong with info and its addition to the new container.

                          PS IN MY OPINION here is a shinning example that code posting is not of that great help - I have repeatedly state what runs and what does not and you started compiling code which did not need to be compiled to find the problem - simple reading thru should have been sufficient to find the problem.
                          But Alex insisted , so you got to find for yourself (!) what rums and what does not, and to prove what ?
                          ...It fails in the subsequent usage....for still unknown reason.
                          However, I am still confident that together we can find the problem...

                          Axel SpoerlA JonBJ 2 Replies Last reply
                          0
                          • A Anonymous_Banned275

                            @JonB ok , AS I said I have accidentally posted wrong copy of the code.
                            With that removed it compiles and when I add to the new container the data shows up in the verifying loop ( as I said before ),
                            there is nothing wrong with info and its addition to the new container.

                            PS IN MY OPINION here is a shinning example that code posting is not of that great help - I have repeatedly state what runs and what does not and you started compiling code which did not need to be compiled to find the problem - simple reading thru should have been sufficient to find the problem.
                            But Alex insisted , so you got to find for yourself (!) what rums and what does not, and to prove what ?
                            ...It fails in the subsequent usage....for still unknown reason.
                            However, I am still confident that together we can find the problem...

                            Axel SpoerlA Offline
                            Axel SpoerlA Offline
                            Axel Spoerl
                            Moderators
                            wrote on last edited by Axel Spoerl
                            #15

                            But Alex insisted

                            Here is what I insisted on:

                            Please also post the entire code, not just fragments.

                            The post contains fragments, and obviously the wrong ones.

                            IN MY OPINION here is a shinning example that code posting is not of that great help

                            In my opinion here is a shining example that posting wrong and incomplete code is not helpful.

                            Software Engineer
                            The Qt Company, Oslo

                            A 1 Reply Last reply
                            2
                            • A Anonymous_Banned275

                              @JonB ok , AS I said I have accidentally posted wrong copy of the code.
                              With that removed it compiles and when I add to the new container the data shows up in the verifying loop ( as I said before ),
                              there is nothing wrong with info and its addition to the new container.

                              PS IN MY OPINION here is a shinning example that code posting is not of that great help - I have repeatedly state what runs and what does not and you started compiling code which did not need to be compiled to find the problem - simple reading thru should have been sufficient to find the problem.
                              But Alex insisted , so you got to find for yourself (!) what rums and what does not, and to prove what ?
                              ...It fails in the subsequent usage....for still unknown reason.
                              However, I am still confident that together we can find the problem...

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

                              @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                              PS IN MY OPINION here is a shinning example that code posting is not of that great help - I have repeatedly state what runs and what does not and you started compiling code which did not need to be compiled to find the problem - simple reading thru should have been sufficient to find the problem.

                              Nope. We need the code. If you want to know what's wrong in it. We have suggested the most likely cause. The RemoteDeviceInfo.append(&info) is wrong, and that's the answer to your original

                              Using debug I do not detect anything in RemoteDeviceInfo

                              1 Reply Last reply
                              2
                              • Axel SpoerlA Axel Spoerl

                                But Alex insisted

                                Here is what I insisted on:

                                Please also post the entire code, not just fragments.

                                The post contains fragments, and obviously the wrong ones.

                                IN MY OPINION here is a shinning example that code posting is not of that great help

                                In my opinion here is a shining example that posting wrong and incomplete code is not helpful.

                                A Offline
                                A Offline
                                Anonymous_Banned275
                                wrote on last edited by
                                #17

                                @Axel-Spoerl NO , YOU GOT COMPLETE WORKing CODE - after the wrong line is removed.

                                Can we get back to the problem and quit bickering , it is getting tiresome.

                                1 Reply Last reply
                                0
                                • Axel SpoerlA Offline
                                  Axel SpoerlA Offline
                                  Axel Spoerl
                                  Moderators
                                  wrote on last edited by
                                  #18

                                  @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                  NO , YOU GOT COMPLETE WORKing CODE - after the wrong line is removed.

                                  Untrue. The code posted is not complete. As an example, the class definition starts with Q_OBJECT => Large parts of the declarations are missing in the first fragment.

                                  The second fragment misses the function name, let alone that I don't see where this unnamed function is called and where info is declared, as @JonB asked.

                                  @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                  Can we get back to the problem

                                  Good idea. Please let's start with what was asked in the beginning: Please post your entire code.

                                  and quit bickering

                                  You don't have to quit bickering all at once. It's totally fine if you fade it out gradually. Or have I misunderstood, and intention was to insult me? Forgiven with a smile! Just have a look at the code of conduct when it suits you.

                                  it is getting tiresome.

                                  Kind of agree.

                                  Software Engineer
                                  The Qt Company, Oslo

                                  A 1 Reply Last reply
                                  3
                                  • Axel SpoerlA Axel Spoerl

                                    @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                    NO , YOU GOT COMPLETE WORKing CODE - after the wrong line is removed.

                                    Untrue. The code posted is not complete. As an example, the class definition starts with Q_OBJECT => Large parts of the declarations are missing in the first fragment.

                                    The second fragment misses the function name, let alone that I don't see where this unnamed function is called and where info is declared, as @JonB asked.

                                    @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                    Can we get back to the problem

                                    Good idea. Please let's start with what was asked in the beginning: Please post your entire code.

                                    and quit bickering

                                    You don't have to quit bickering all at once. It's totally fine if you fade it out gradually. Or have I misunderstood, and intention was to insult me? Forgiven with a smile! Just have a look at the code of conduct when it suits you.

                                    it is getting tiresome.

                                    Kind of agree.

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on last edited by
                                    #19

                                    @Axel-Spoerl said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                    The second fragment misses the function name, let alone that I don't see where this unnamed function is called and where info is declared, as @JonB asked.

                                    What is " second fragment " ?
                                    The code contains two functions /methods....

                                    Please be more specific and make use of the requested (!) code and highlight where is " the missing function" problem.

                                    Since the add of info works and is verified in the code - as I repeatedly stated - the source of info is material.
                                    JonB is a nice guy , but this time on wrong track...

                                    Please quit stalling with silly requests for more code - if the code is missing a function it would not compile , duh...

                                    Axel SpoerlA JonBJ 2 Replies Last reply
                                    0
                                    • A Anonymous_Banned275

                                      @Axel-Spoerl said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                      The second fragment misses the function name, let alone that I don't see where this unnamed function is called and where info is declared, as @JonB asked.

                                      What is " second fragment " ?
                                      The code contains two functions /methods....

                                      Please be more specific and make use of the requested (!) code and highlight where is " the missing function" problem.

                                      Since the add of info works and is verified in the code - as I repeatedly stated - the source of info is material.
                                      JonB is a nice guy , but this time on wrong track...

                                      Please quit stalling with silly requests for more code - if the code is missing a function it would not compile , duh...

                                      Axel SpoerlA Offline
                                      Axel SpoerlA Offline
                                      Axel Spoerl
                                      Moderators
                                      wrote on last edited by
                                      #20

                                      @AnneRanch
                                      To summarize:
                                      @Christian Ehrlicher and @JonB, both truly nice guys, have already told you what the problem is: A pointer to a (probably) stack allocated object info is added to the list RemoteDeviceInfo. When it goes out of scope, the pointer points to a deleted object and things go banana from there. That's the most likely scenario based on the code fragments we see.

                                      In the next post, your call out @JonB, apparently in disagreement with the current findings.

                                      Very interestingly you twist things around, blaming us for not finding whatever you would accept as being the problem:

                                      simple reading thru should have been sufficient to find the problem.

                                      In essence that means:

                                      • you know you have a problem
                                      • you don't know what it is
                                      • you are certain that it's not, what @Christian-Ehrlicher and @JonB (very capable experts) say it is - even though they point at something obviously wrong
                                      • on the other hand you claim (and blame), that the code fragments posted must be sufficient for others to figure out your problem

                                      Question: Have you read and understood what we believe could be (part of) the problem?

                                      Three behaviors make it rather hard to dive deeper

                                      • consistently ignoring requests to post your entire code (for clarity: entire means all, everything, the whole)
                                      • such requests being called "silly", "bickering" (thanks by the way, it has made me laugh out loud)
                                      • no feedback on the findings pointed out earlier (like e.g. "Ok, thanks, I will test a different approach and let you know")

                                      "Simple reading thru should have been sufficient to find the problem" => I have just done as you said.
                                      My count is:

                                      • 3 refusals to co-operate
                                      • 2 insults
                                      • 1 thank you
                                      • 1 apology (none for the insults, though)
                                      • 0 please

                                      My finding: Communicating with you isn't fun. IMHO, communication is your problem.

                                      Good bye, @AnneRanch

                                      Software Engineer
                                      The Qt Company, Oslo

                                      1 Reply Last reply
                                      4
                                      • A Anonymous_Banned275

                                        @Axel-Spoerl said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                        The second fragment misses the function name, let alone that I don't see where this unnamed function is called and where info is declared, as @JonB asked.

                                        What is " second fragment " ?
                                        The code contains two functions /methods....

                                        Please be more specific and make use of the requested (!) code and highlight where is " the missing function" problem.

                                        Since the add of info works and is verified in the code - as I repeatedly stated - the source of info is material.
                                        JonB is a nice guy , but this time on wrong track...

                                        Please quit stalling with silly requests for more code - if the code is missing a function it would not compile , duh...

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

                                        @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                        JonB is a nice guy , but this time on wrong track...

                                        Thanks. Why don't you show where info is declared since this remains the candidate for the bad behaviour from what we have seen so far?

                                        A 1 Reply Last reply
                                        3
                                        • JonBJ JonB

                                          @AnneRanch said in QList<const QBluetoothDeviceInfo* declaration / definiton problem:

                                          JonB is a nice guy , but this time on wrong track...

                                          Thanks. Why don't you show where info is declared since this remains the candidate for the bad behaviour from what we have seen so far?

                                          A Offline
                                          A Offline
                                          Anonymous_Banned275
                                          wrote on last edited by
                                          #22

                                          @JonB I have added some more debugging code , basically bypassing the range loop after the "append".

                                          RemoteDeviceInfo.append(&info);
                                          text = "DIRECT ";
                                          text += RemoteDeviceInfo.at(0)->name();
                                          qDebug()<< text;
                                          qDebug()<< text;
                                          return;

                                          here is the output and contents of RemoteDeviceInfo:

                                          " TASK START setup connect void SettingsDialog::RunPairing()"
                                          "\n TASK addDevice "
                                          " device address ED:C3:50:CA:6D:29"
                                          " device name OontZ Angle solo D29\n"
                                          " TASK pair device name OontZ Angle solo D29\n"
                                          " TASK pairingStatus OontZ Angle solo D292"
                                          "DIRECT OontZ Angle solo D29"

                                          or when Bluetooth "works better" - I have a real issue , outside of this problem

                                          " TASK continue...void SettingsDialog::RunPairing()"
                                          "\n TASK addDevice "
                                          " device address 98:D3:31:F8:39:33"
                                          " device name SPP-CA\n"
                                          " TASK pair device name SPP-CA\n"
                                          " TASK pairingStatus SPP-CA0"
                                          "DIRECT SPP-CA"
                                          "DIRECT SPP-CA"
                                          "\n TASK addDevice "
                                          " device address 98:D3:31:FC:10:73"
                                          " device name HC-05\n"
                                          " TASK pair device name HC-05\n"
                                          " TASK pairingStatus HC-050"
                                          "DIRECT HC-05"
                                          "DIRECT HC-05"
                                          "\n TASK addDevice "
                                          " device address 98:D3:31:FB:12:EB"
                                          " device name HC-05\n"
                                          " TASK pair device name HC-05\n"
                                          " TASK pairingStatus HC-050"
                                          "DIRECT HC-05"
                                          "DIRECT HC-05"

                                          This is how the other "fragment " looks now:

                                          void SettingsDialog::on_applyButton_11_clicked()
                                          {
                                              text = " Direct access ";
                                              text += RemoteDeviceInfo.at(0)->name();
                                              qDebug()<< text;
                                              return;
                                          
                                          
                                          

                                          however - this morning Bluetooth refuses to cooperate so I'll post the output of the
                                          void SettingsDialog::on_applyButton_11_clicked()
                                          later.

                                          Thanks for not giving up and your continuing interest in resolving this issue, appreciate that very much.
                                          Cheers

                                          JonBJ 1 Reply Last reply
                                          0

                                          • Login

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