QList<const QBluetoothDeviceInfo* declaration / definiton problem
-
Adding to @Christian-Ehrlicher:
RemoteDeviceInfo = new QBluetoothHostInfo();
assigns pointer to a heap allocated
BluetoothHostInfo
to a member variable, defined as aQList<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.
-
@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. -
@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. -
@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....
-
@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 thatinfo
actually declared? The code you have posted won't compile that line for theinfo
, not just thenew
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);
-
@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... -
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.
-
@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 originalUsing debug I do not detect anything in RemoteDeviceInfo
-
@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.
-
@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.
-
@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...
-
@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 objectinfo
is added to the listRemoteDeviceInfo
. 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
-
@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? -
@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 -
@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.
- Do you still have line reading
-
@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 -
@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.
-
@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 whereinfo
is declared. As you please. I leave it to others to figure better. -
@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); }
-
@AnneRanch
I can't tell from that from the above fragment. It depends whereinfo
is declared. If you would answer that we would know.