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. Adding QBluetoothDeviceInfo to QList error
Forum Update on Monday, May 27th 2025

Adding QBluetoothDeviceInfo to QList error

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 2 Posters 469 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 10 Feb 2023, 13:05 last edited by
    #1

    Here is a code snippet which oasses "intelisese" ("append: is a valid function ) , but gives me an error.

    void MainWindow_BT_Terminal::addDevice(const QBluetoothDeviceInfo &info)
    {
        text = "add remote device to list... ";
        text += " ";
        qDebug()<< text;
    
        // QList<QBluetoothDeviceInfo*> RemoteDevicesList;
        RemoteDevicesList.append(info);
        
    

    I do not understand why I am getting this error.

    /mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/PROJECTS/RECOVERY/BLUETOOTH/SOURCE/CCC_SOURCE/terminal_SERIAL_BLUETOOTH_VER_1/terminal_SERIAL_BLUETOOTH/terminal_BLUETOOTH/mainwindow_BT_Terminal.cpp:799: error: no matching member function for call to 'append'
    mainwindow_BT_Terminal.cpp:799:23: error: no matching member function for call to 'append'
        RemoteDevicesList.append(info);
        ~~~~~~~~~~~~~~~~~~^~~~~~
    /home/nov25-1/Qt/Nov26/5.15.2/gcc_64/include/QtCore/qlist.h:210:10: note: candidate function not viable: no known conversion from 'const QBluetoothDeviceInfo' to 'QBluetoothDeviceInfo *const' for 1st argument
        void append(const T &t);
             ^
    /home/nov25-1/Qt/Nov26/5.15.2/gcc_64/include/QtCore/qlist.h:211:10: note: candidate function not viable: no known conversion from 'const QBluetoothDeviceInfo' to 'const QList<QBluetoothDeviceInfo *>' for 1st argument
        void append(const QList<T> &t);
             ^
    

    could somebody PLEASE explain to me why I am getting the error and OFFER A SOLUTION ?

    PS I do not need a confirmation that I am getting an error, I need a solution.

    Thanks

    C 1 Reply Last reply 10 Feb 2023, 13:47
    0
    • A Anonymous_Banned275
      10 Feb 2023, 13:05

      Here is a code snippet which oasses "intelisese" ("append: is a valid function ) , but gives me an error.

      void MainWindow_BT_Terminal::addDevice(const QBluetoothDeviceInfo &info)
      {
          text = "add remote device to list... ";
          text += " ";
          qDebug()<< text;
      
          // QList<QBluetoothDeviceInfo*> RemoteDevicesList;
          RemoteDevicesList.append(info);
          
      

      I do not understand why I am getting this error.

      /mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/PROJECTS/RECOVERY/BLUETOOTH/SOURCE/CCC_SOURCE/terminal_SERIAL_BLUETOOTH_VER_1/terminal_SERIAL_BLUETOOTH/terminal_BLUETOOTH/mainwindow_BT_Terminal.cpp:799: error: no matching member function for call to 'append'
      mainwindow_BT_Terminal.cpp:799:23: error: no matching member function for call to 'append'
          RemoteDevicesList.append(info);
          ~~~~~~~~~~~~~~~~~~^~~~~~
      /home/nov25-1/Qt/Nov26/5.15.2/gcc_64/include/QtCore/qlist.h:210:10: note: candidate function not viable: no known conversion from 'const QBluetoothDeviceInfo' to 'QBluetoothDeviceInfo *const' for 1st argument
          void append(const T &t);
               ^
      /home/nov25-1/Qt/Nov26/5.15.2/gcc_64/include/QtCore/qlist.h:211:10: note: candidate function not viable: no known conversion from 'const QBluetoothDeviceInfo' to 'const QList<QBluetoothDeviceInfo *>' for 1st argument
          void append(const QList<T> &t);
               ^
      

      could somebody PLEASE explain to me why I am getting the error and OFFER A SOLUTION ?

      PS I do not need a confirmation that I am getting an error, I need a solution.

      Thanks

      C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 10 Feb 2023, 13:47 last edited by
      #2

      why I am getting the error

      Your list holds pointers and you're trying to pass an object reference to append().

      OFFER A SOLUTION

      Change the list type to match what you're passing or change what you're passing to match the list type.

      A 1 Reply Last reply 11 Feb 2023, 17:25
      2
      • C Chris Kawa
        10 Feb 2023, 13:47

        why I am getting the error

        Your list holds pointers and you're trying to pass an object reference to append().

        OFFER A SOLUTION

        Change the list type to match what you're passing or change what you're passing to match the list type.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on 11 Feb 2023, 17:25 last edited by
        #3

        @Chris-Kawa Let me ask really stupid question - can I then select the "value" or pointer myself? I am having few issues implementing QList.

        C 1 Reply Last reply 11 Feb 2023, 18:07
        0
        • A Anonymous_Banned275
          11 Feb 2023, 17:25

          @Chris-Kawa Let me ask really stupid question - can I then select the "value" or pointer myself? I am having few issues implementing QList.

          C Online
          C Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on 11 Feb 2023, 18:07 last edited by Chris Kawa 2 Nov 2023, 18:10
          #4

          @AnneRanch QList is a container. You put stuff in and you take stuff out of containers. I'm not sure I understand. What do you mean by "select a value"?

          Example:

          QList<QBluetoothDeviceInfo> RemoteDevicesList; //list of values
          
          RemoteDevicesList.append(info); //append a value (copy it into the back of the list)
          RemoteDevicesList.insert(17, info); //insert a copy of info at position 17
          RemoteDevicesList.removeFirst(); //remove first element
          RemoteDevicesList.removeLast(); //remove last element
          RemoteDevicesList.removeOne(info); //remove first element which value equals info
          QBluetoothDeviceInfo i1 = RemoteDevicesList.first(); //copy first element out to i1 variable
          QBluetoothDeviceInfo i2 = RemoteDevicesList.last(); //copy first element out to i2 variable
          QBluetoothDeviceInfo i3 = RemoteDevicesList.at(42); //copy 42nd element out to i3 variable
          

          The above is when you have a list of values. If you have a list of pointers it's pretty much the same, but you deal with addresses, so & when you want to take an address of an object and * when you want to get an object a pointer points to:

          QList<QBluetoothDeviceInfo*> RemoteDevicesList; //list of pointers
          
          RemoteDevicesList.append(&info); //append an address of info object (pointer) to the back of the list
          RemoteDevicesList.insert(17, &info); //insert a pointer to the info object at position 17
          QBluetoothDeviceInfo i1 = *RemoteDevicesList.first(); //take the first pointer from the list, dereference it with * and copy it to i1 variable
          QBluetoothDeviceInfo* i2 = RemoteDevicesList.first(); //take the first pointer from the list and copy it to i2 variable
          

          Keep in mind that when you're dealing with pointers you have to make sure the objects they point to are still alive, otherwise the pointers will point to garbage and cause a crash when you try to access the objects through them.

          A 1 Reply Last reply 14 May 2023, 20:42
          1
          • C Chris Kawa
            11 Feb 2023, 18:07

            @AnneRanch QList is a container. You put stuff in and you take stuff out of containers. I'm not sure I understand. What do you mean by "select a value"?

            Example:

            QList<QBluetoothDeviceInfo> RemoteDevicesList; //list of values
            
            RemoteDevicesList.append(info); //append a value (copy it into the back of the list)
            RemoteDevicesList.insert(17, info); //insert a copy of info at position 17
            RemoteDevicesList.removeFirst(); //remove first element
            RemoteDevicesList.removeLast(); //remove last element
            RemoteDevicesList.removeOne(info); //remove first element which value equals info
            QBluetoothDeviceInfo i1 = RemoteDevicesList.first(); //copy first element out to i1 variable
            QBluetoothDeviceInfo i2 = RemoteDevicesList.last(); //copy first element out to i2 variable
            QBluetoothDeviceInfo i3 = RemoteDevicesList.at(42); //copy 42nd element out to i3 variable
            

            The above is when you have a list of values. If you have a list of pointers it's pretty much the same, but you deal with addresses, so & when you want to take an address of an object and * when you want to get an object a pointer points to:

            QList<QBluetoothDeviceInfo*> RemoteDevicesList; //list of pointers
            
            RemoteDevicesList.append(&info); //append an address of info object (pointer) to the back of the list
            RemoteDevicesList.insert(17, &info); //insert a pointer to the info object at position 17
            QBluetoothDeviceInfo i1 = *RemoteDevicesList.first(); //take the first pointer from the list, dereference it with * and copy it to i1 variable
            QBluetoothDeviceInfo* i2 = RemoteDevicesList.first(); //take the first pointer from the list and copy it to i2 variable
            

            Keep in mind that when you're dealing with pointers you have to make sure the objects they point to are still alive, otherwise the pointers will point to garbage and cause a crash when you try to access the objects through them.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on 14 May 2023, 20:42 last edited by
            #5

            @Chris-Kawa I did not realize I made a duplicate post , so I am adding my goof here . Sorry for wasting space.
            I think I got the concept of containers, but I am obviously missing something else.

            What am I missing in my code ?

            Decaration

            QList<const QBluetoothDeviceInfo* > RemoteDeviceInfo;

            This works

            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);
                    }
            

            when I attempt to verify RemoteDeviceInfo) using another method

            it fails

            if(!RemoteDeviceInfo.isEmpty()) passes OK
            {
            for (auto &device:RemoteDeviceInfo)
            {
            text = " For loop test ";
            qDebug() << text;
            text = " device address \n";
            text += device->address().toString(); fails here
            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);

                                    }
                                }
                            }
            

            My debug shows no contents in RemoteDeviceInfo when used in another method.

            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