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 18.5k 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

    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
                            • A Anonymous_Banned275

                              @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 Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #23

                              @AnneRanch

                              • Do you still have line reading RemoteDeviceInfo.append(&info); in your code? "Yes" or "No"?
                              • If "Yes" can you please, please, please, please show where info is declared?

                              That's it, 2 questions, 10 seconds to answer.

                              A 1 Reply Last reply
                              2
                              • JonBJ JonB

                                @AnneRanch

                                • Do you still have line reading RemoteDeviceInfo.append(&info); in your code? "Yes" or "No"?
                                • If "Yes" can you please, please, please, please show where info is declared?

                                That's it, 2 questions, 10 seconds to answer.

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

                                @JonB YES
                                but sorry my class FULL CODE cannot be posted here it exceeds the allowed size.
                                You just have to take my word that "info" DOES contains data- as the debug output shows.

                                I suspect I MAY be running the class constructor multiple times....

                                Here is what I get when I attempt to debug here

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

                                Screenshot from 2023-05-16 09-22-30.png

                                J.HilkJ JonBJ 2 Replies Last reply
                                0
                                • A Anonymous_Banned275

                                  @JonB YES
                                  but sorry my class FULL CODE cannot be posted here it exceeds the allowed size.
                                  You just have to take my word that "info" DOES contains data- as the debug output shows.

                                  I suspect I MAY be running the class constructor multiple times....

                                  Here is what I get when I attempt to debug here

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

                                  Screenshot from 2023-05-16 09-22-30.png

                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #25

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

                                  I suspect I MAY be running the class constructor multiple times....

                                  thats literally impossible.
                                  The constructor is the only "function " that can not be called manually.

                                  You may have multiple instances of a class that may or may not shadow each other, hard to tell without the full class but this error message/ debug output shows that your BluetoothDeviceInfo object is invalid/uninitialized or already destroyed.

                                  Like previously suspected.


                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  A 1 Reply Last reply
                                  1
                                  • A Anonymous_Banned275

                                    @JonB YES
                                    but sorry my class FULL CODE cannot be posted here it exceeds the allowed size.
                                    You just have to take my word that "info" DOES contains data- as the debug output shows.

                                    I suspect I MAY be running the class constructor multiple times....

                                    Here is what I get when I attempt to debug here

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

                                    Screenshot from 2023-05-16 09-22-30.png

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

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

                                    @JonB YES
                                    but sorry my class FULL CODE cannot be posted here it exceeds the allowed size.

                                    So we know the code still has RemoteDeviceInfo.append(&info);, but we still can't know/be told where info is declared. As you please. I leave it to others to figure better.

                                    A 1 Reply Last reply
                                    1
                                    • JonBJ JonB

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

                                      @JonB YES
                                      but sorry my class FULL CODE cannot be posted here it exceeds the allowed size.

                                      So we know the code still has RemoteDeviceInfo.append(&info);, but we still can't know/be told where info is declared. As you please. I leave it to others to figure better.

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

                                      @JonB Would this be OK ?

                                                 if(info.isValid())
                                                  {
                                      
                                                  RemoteDeviceInfo.append(&info);
                                                  text = "TEST DIRECT RemoteDeviceInfo.append(&info)";
                                                  text += RemoteDeviceInfo.at(0)->name();
                                                   text += RemoteDeviceInfo.at(0)->name();
                                                   m_ui->plainTextEdit->appendPlainText(text);
                                                  qDebug()<< text;
                                                   qDebug()<< text;
                                                  }
                                                  else
                                                  {
                                                      text = "Failed info - info.isValid()";
                                                      //text += RemoteDeviceInfo.at(0)->name();
                                                      // text += RemoteDeviceInfo.at(0)->name();
                                                      qDebug()<< text;
                                                       qDebug()<< text;
                                                       m_ui->plainTextEdit->appendPlainText(text);
                                      
                                                  }
                                      
                                      
                                      JonBJ Axel SpoerlA 2 Replies Last reply
                                      0
                                      • A Anonymous_Banned275

                                        @JonB Would this be OK ?

                                                   if(info.isValid())
                                                    {
                                        
                                                    RemoteDeviceInfo.append(&info);
                                                    text = "TEST DIRECT RemoteDeviceInfo.append(&info)";
                                                    text += RemoteDeviceInfo.at(0)->name();
                                                     text += RemoteDeviceInfo.at(0)->name();
                                                     m_ui->plainTextEdit->appendPlainText(text);
                                                    qDebug()<< text;
                                                     qDebug()<< text;
                                                    }
                                                    else
                                                    {
                                                        text = "Failed info - info.isValid()";
                                                        //text += RemoteDeviceInfo.at(0)->name();
                                                        // text += RemoteDeviceInfo.at(0)->name();
                                                        qDebug()<< text;
                                                         qDebug()<< text;
                                                         m_ui->plainTextEdit->appendPlainText(text);
                                        
                                                    }
                                        
                                        
                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by JonB
                                        #28

                                        @AnneRanch
                                        I can't tell from that from the above fragment. It depends where info is declared. If you would answer that we would know.

                                        A 1 Reply Last reply
                                        1
                                        • A Anonymous_Banned275

                                          @JonB Would this be OK ?

                                                     if(info.isValid())
                                                      {
                                          
                                                      RemoteDeviceInfo.append(&info);
                                                      text = "TEST DIRECT RemoteDeviceInfo.append(&info)";
                                                      text += RemoteDeviceInfo.at(0)->name();
                                                       text += RemoteDeviceInfo.at(0)->name();
                                                       m_ui->plainTextEdit->appendPlainText(text);
                                                      qDebug()<< text;
                                                       qDebug()<< text;
                                                      }
                                                      else
                                                      {
                                                          text = "Failed info - info.isValid()";
                                                          //text += RemoteDeviceInfo.at(0)->name();
                                                          // text += RemoteDeviceInfo.at(0)->name();
                                                          qDebug()<< text;
                                                           qDebug()<< text;
                                                           m_ui->plainTextEdit->appendPlainText(text);
                                          
                                                      }
                                          
                                          
                                          Axel SpoerlA Offline
                                          Axel SpoerlA Offline
                                          Axel Spoerl
                                          Moderators
                                          wrote on last edited by
                                          #29

                                          @AnneRanch
                                          No, because isValid() is irrelevant for the error. It The crash happens in the attempt to access a deleted object. Probably it just goes out of scope after the adding function has returned. This is what everybody tries to explain, and it seems to be hard to believe for you. No matter what you try, it is wrong to store stack-allocated objects in a list member and access them outside their scope. It might even occasionally work, as long as their freed memory remains untouched. But every address sanitizer will scream out a use-after-free exception.

                                          You probably assume that once it’s in the container, the object’s lifetime is bound to that container. Kind of an understandable guess: You stick candy in a box and close it. You expect it stays there. And it does, but it turns foul because it expires in the box. Boom, that’s your crash. If you ask the candy if it’s valid, it may even say yes, although it stinks already.

                                          The right solution I your case is probably to allocate info on the heap with new. Change the list of objects into a list of pointers. Don’t forget to delete the heap allocated objects in the destructor, best with qDeleteAll.

                                          Software Engineer
                                          The Qt Company, Oslo

                                          1 Reply Last reply
                                          3

                                          • Login

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