Appending QStringList crashes
-
I have a large program which does many things at once (including multiple threads)
and a small addition to a particular part of my code crashes it, in the mainWindow class a pointer QStringList exists that stores a set of mac addresses, this QStringList is initialised initially with ownedMacAddresses = &tempStringList, and later on in the code prompted by the user a mac address can be found and passed by way of signal to a slot which processes it, which is fine (QString mac is passed through the connection), however, when I try to ownedMacAddresses->append(mac), it crashes when the user clicks the button at this point, why?
-
I have a large program which does many things at once (including multiple threads)
and a small addition to a particular part of my code crashes it, in the mainWindow class a pointer QStringList exists that stores a set of mac addresses, this QStringList is initialised initially with ownedMacAddresses = &tempStringList, and later on in the code prompted by the user a mac address can be found and passed by way of signal to a slot which processes it, which is fine (QString mac is passed through the connection), however, when I try to ownedMacAddresses->append(mac), it crashes when the user clicks the button at this point, why?
-
In fact it seems to crash using 'mac' for anything at all outside of using it to initialize a class and output it through qDebug() once, Its hard for me to show the code as it is on a different platform.
-
In fact it seems to crash using 'mac' for anything at all outside of using it to initialize a class and output it through qDebug() once, Its hard for me to show the code as it is on a different platform.
-
I have a large program which does many things at once (including multiple threads)
and a small addition to a particular part of my code crashes it, in the mainWindow class a pointer QStringList exists that stores a set of mac addresses, this QStringList is initialised initially with ownedMacAddresses = &tempStringList, and later on in the code prompted by the user a mac address can be found and passed by way of signal to a slot which processes it, which is fine (QString mac is passed through the connection), however, when I try to ownedMacAddresses->append(mac), it crashes when the user clicks the button at this point, why?
-
@Hubbard said in Appending QStringList crashes:
&tempStringList
Has
tempStringList
gone out of scope? -
@ollarch You're right...
none of it is the problem apart from trying to use ownedMacAddresses
justqDebug() << ownedMacAddresses[0];
in the slot
crashes the program
@Hubbard said in Appending QStringList crashes:
qDebug() << ownedMacAddresses[0];
This can't work the way you expect it to work, because ownedMacAddresses is a pointer. If you want to do it this way then so:
qDebug() << (*ownedMacAddresses)[0];
"Still crashes inside the slot
qDebug() << ownedMacAddresses->at(0);" - did you try to place a breakpoint at that line and see whether ownedMacAddresses is a valid pointer? Also - what kind of crash is it (SIGSEGV?)? -
@Hubbard Mit "valid pointer" I mean a pointer pointing to reserved memory and not to nirvana.
QStringList* p1; // Invalid pointer QStringList* p2 = new QStringList(); // Valid pointer
"Index out of range at element 0" means that you do not have any elements in the list. Check that with:
qDebug() << currentMacs->size();