I have code that supports both native C++ types as well as Qt types. For example there are string‘s and QString‘s which are “equivalent.”
I have 2 functions, one that takes string‘s and one that takes QString‘s. The QString version converts the parameters to string‘s and then calls the string version of the function.
Here is some generic code of the problem:
int myClass::LoadQString(const QString &tagName, QString &toReturn)
{
string tag = tagName.toStdString();
string ret = toReturn.toStdString();
//string& ret = toReturn.toStdString(); //This gives me an error
return LoadString(tag, ret);
}
int myClass::LoadString(const string& tagName, string& toReturn)
{
toReturn = "hello world!";
...
}
So, this code will compile and run…however, when I call LoadQString() the second parameter is an empty QString once it returns. You can see in my commented line where I tried string& ret = ... to get the reference to work. If I call LoadString() and then check the value of toReturn when it returns, it will be “hello world!” as expected.
Just trying to get the LoadQString() to work properly.
Thanks for all your help!
You should convert from
std::stringback toQStringafterstd::stringversion call