View Full Version : Char* <-> QString implicit conversion
kingfinn
12th March 2010, 16:58
Hey there,
for some reason, if i have a function which has QString Arguments and I pass it a char*, sometimes it works and sometimes I get an Error?
Why is this and how to work around?
high_flyer
12th March 2010, 17:04
I get an Error?
What error?
Can you paste it here?
kingfinn
12th March 2010, 17:07
The function declaration:
QList<QStringList> select(QString& from, QString& where, QStringList* what=0);
How I call it:
QList<QStringList> dirs = svh->select("dirs", QString().setNum(dir->getId()));
The Error I get:
/home/finn/client_gallery/dirparser.cpp:24: error: no matching function for call to ‘SqlViaHttp::select(const char [5], QString&)’
//EDIT:
Ahh, ok, I know so the solution.
I have to use QString instead of QString& in the Declaration.
Why is that?
high_flyer
15th March 2010, 08:26
I have to use QString instead of QString& in the Declaration.
Why is that?
You don't have to change the declaration, you can change the way you use call the function.
You declared it with a reference, so you need to pass a reference, but you have passed a literal string.
Your declaration will work if you call it like this:
QString strDirs = "dirs";
QList<QStringList> dirs = svh->select(strDirs , QString().setNum(dir->getId()));
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.