Cannot convert QString to int in assignment
-
-
https://duckduckgo.com/?q=error+"cannot+convert+QString+to+int+in+assignment+qt"
There are no hits on the search engines for this error though, where can I find documentation on errors?
-
This is more a c++ related error than qt specific. It has to do with type casting. You tried to assign QString to an int at line 4.
[quote author="aetbanan" date="1335203805"]@
int iTime;
QString newline;
bool ok;
iTime = newline.toInt(&ok, 10);@
[/quote]In such situations c++ tries to convert one type to another but those types must be compatible or in case of object assignment should offer copy constructors and/or assignment operators that handle that conversion. The reason you didn't find any related hits on the search engines is that the combination of incompatible types or objects is unlimited and you created one of them.
For more information on c++ type casting check http://www.cplusplus.com/doc/tutorial/typecasting/
-
[quote author="aetbanan" date="1335203805"]
@
int iTime;
QString newline;
bool ok;
iTime = newline.toInt(&ok, 10);
@
[/quote]This works perfectly. Did you modify your original post? If so, please leave a note - this whole thread doesn't make sense anymore for anyone jumping in later.
-
Volker is correct. This code works fine but I did the mistake of taking as fact that the error did come up with the above code.This could be created in situation such as
@int iTime;
QString newline;
bool ok;
iTime = newline(10)@
where by mistake you missed to use the member function and used QString constructor. I must read more carefully and imagine less I guess.