Comparison between distinct pointer types 'QString*' and 'const char*' lacks a cast [-fpermissive]
-
wrote on 9 Jul 2014, 11:51 last edited by
I had a QString inizialized in the .h file
@
QString *str;
@In the .cpp constructor, str id declared
@
active = new QString;
if (str->isEmpty()) { *str = "foobar"; }
@Now, when I try to set an int variable in this way
@
int num = (str == "foobar") ? 5: 6;
@Qt Creator sends me this error:
"comparison between distinct pointer types 'QString*' and 'const char*' lacks a cast [-fpermissive]"
I guess that I have not run a cast, but what exactly?
Could you help me? -
Hi,
You should dereference str using * operator during comparison.
This will work,
@
int num = (*str == "foobar") ? 5: 6;
@ -
wrote on 9 Jul 2014, 12:15 last edited by
[quote author="p3c0" date="1404907893"]Hi,
You should dereference str using * operator during comparison.
This will work,
@
int num = (*str == "foobar") ? 5: 6;
@[/quote]The program crash on start
-
In your first post i see you have initialised active but not str. Is that a typo ?
-
wrote on 9 Jul 2014, 12:22 last edited by
No, i misswrited the variable name. str is correct
-
So is it still crashing after initialising str ? I mean after doing this,
@
QString *str = new QString;
if (str->isEmpty()) { *str = "foobar"; }
int num = (*str == "foobar") ? 5: 6;
@ -
wrote on 9 Jul 2014, 12:36 last edited by
[quote author="p3c0" date="1404908755"]So is it still crashing after initialising str ? I mean after doing this,
@
QString *str = new QString;
if (str->isEmpty()) { *str = "foobar"; }
int num = (*str == "foobar") ? 5: 6;
@[/quote]Solved
-
Good. You can mark the post as solved.
-
Hi,
Out of curiosity, why are you using a pointer to a QString ?
-
This post is deleted!