Hi, I want to return QString from this function:
Is this good way? And how can i call the function and use this QString value in my main program?
Thanks
Hi, I want to return QString from this function:
Is this good way? And how can i call the function and use this QString value in my main program?
Thanks
Last edited by Rondle; 9th November 2012 at 18:24.
learn to c++
Qt Code:
class myclass { public: std::string func() { return "abc"; } void use_func() { std::string s = func(); // do something with s... } }; int main() { myclass mc; mc.use_func(); }To copy to clipboard, switch view to plain text mode
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
You can call this function by:
QString returnValue = postLogin(reply);
make this returnValue parameter declaration as global one.
Yes.
Gokulnathvc already answered that when you are in the scope of the MainWindow class (which is likely).And how can i call the function and use this QString value in my main program?
You can treat QString as a return value just like you would treat any of the basic types, e.g. int or bool.
QString, like a lot of other Qt classes, uses a technique calles "implicit sharing", meaing that copying a QString value is not incurring the cost (as in CPU and memory usage) of copying the actual string data. So like returning an int it is very cheap.
Cheers,
_
Bookmarks