Reputation: 1672
What is the reason for the choice of API below:
QString QString::fromStdString(const std::string & str) [static]
Why is there a need for calling a static function when we could have a constructor as follows:
QString::QString(const std::string & str)
There are similar constructors for the c string representation (char*), std::string being the exception. What is the reason for that?
Upvotes: 0
Views: 407
Reputation: 8982
Qt predates explicit
constructors, and it can't break its existing clients gratuitously. One other reason would be that std::string
and QString
are not necessarily in the same encoding/codepage and the static methods make explicit that some more expensive conversion is happening.
Upvotes: 2