
Originally Posted by
TheRonin
shouldn't the fact that i immediately (almost) copy the data help me in this situation?
No, it won't help you, because "data" will be destroyed when getChars() returns and you'll get a dangling pointer. No matter how fast you will copy the string, still you'll be accessing deallocated data.
Either use something like this:
const char* getChars(){
return qstrcpy( data.toUtf8().constData() );
}
stringStruct checkChars(){
stringStruct str;
str.setBuffer( getChars() );
return str;
}
const char* getChars(){
QString data = QString("asdf");
return qstrcpy( data.toUtf8().constData() );
}
stringStruct checkChars(){
stringStruct str;
str.setBuffer( getChars() );
return str;
}
To copy to clipboard, switch view to plain text mode
or
std::string getChars(){
return std::string( data.toUtf8().constData() );
}
stringStruct checkChars(){
stringStruct str = getChars().c_str();
return str;
}
std::string getChars(){
QString data = QString("asdf");
return std::string( data.toUtf8().constData() );
}
stringStruct checkChars(){
stringStruct str = getChars().c_str();
return str;
}
To copy to clipboard, switch view to plain text mode
or simply:
stringStruct getChars(){
stringStruct str = data.toUtf8().constData();
return str;
}
stringStruct checkChars(){
return getChars();
}
stringStruct getChars(){
QString data = QString("asdf");
stringStruct str = data.toUtf8().constData();
return str;
}
stringStruct checkChars(){
return getChars();
}
To copy to clipboard, switch view to plain text mode
Bookmarks