我不明白为什么std::string
在将它传递给构造函数时转换为 QString 。这是一个小例子:
class StringHandler
{
private:
QString str;
public:
StringHandler(QString s): str(s) {}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string str = "string";
QString qstr(str); // it gives error there are no constructor QString(std::string)
StringHandler handler(QString(str));//it does not give an error. Why?
return a.exec();
}
编辑:
class StringHandler
{
public:
StringHandler(QString s): str(s) {}
QString str;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::string str = "string";
StringHandler handler(QString(str));//Here should be error, but there no error. Why?
qDebug()<<handler.str; //Error is here: request for member 'str' in 'handler', which is of non-class type 'StringHandler(QString)'
return a.exec();
}