C++ 我能';t在Qt类之外的Qt 5.5中使用tr()

C++ 我能';t在Qt类之外的Qt 5.5中使用tr(),c++,qt,tr,C++,Qt,Tr,我是个初学者,在Qt中实现tr函数时遇到了一个问题。如果我在Qt类之外使用tr(“string”),我会得到错误。 我找到了应该在tr()之前使用QObject::的信息,但是如果我尝试使用 temp += QObject::tr("Example"); // temp is std::string 我犯了个错误 C2679: binary '+=' : no operator found which takes a right-hand operand of type 'QString' (

我是个初学者,在Qt中实现tr函数时遇到了一个问题。如果我在Qt类之外使用tr(“string”),我会得到错误。 我找到了应该在tr()之前使用QObject::的信息,但是如果我尝试使用

temp += QObject::tr("Example"); // temp is std::string
我犯了个错误

C2679: binary '+=' : no operator found which takes a right-hand operand of type 'QString' (or there is no acceptable conversion)
C2665: 'QString::fromUtf8' : none of the 2 overloads could convert all the argument types
另一个例子:

    QString filename="example.txt";
    QFile log(QDir::currentPath() + "//" + filename);
    if ( log.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text) )
    {
    QTextStream plik( &log );
    plik.setCodec("UTF-8");
    (...)
    plik << QString::fromUtf8(QObject::tr("Example2")); // Error
    }

有人能帮我解决这个问题吗?

Qt有这么多的访问器,还有

对于需要转换为Utf8字节数组的流:

plik << QObject::tr("Example2").toUtf8(); // fixed

plik C2660:'QString::toUtf8':函数不接受1个参数是否有其他修复方法?修复了第一种情况。好的,它可以工作-谢谢。但是我问题的第一个错误是什么呢?我有20个这样的错误。。。
plik << QObject::tr("Example2").toUtf8(); // fixed
plik << QObject::tr("Example2"); // will do