Question

I study some Qt3 code, My enviroment is QT 4 commercial, VS2010 with qt-addin. when I add the preprocessor "QT3_SUPPORT", the QString always with some error info like this:

1>  main.cpp
1>main.cpp(18): error C2248: 'QString::operator QNoImplicitBoolCast' : cannot access private member declared in class 'QString'
1>          c:\qt\4.8.4\include\qtcore\../../src/corelib/tools/qstring.h(561) : see declaration of 'QString::operator QNoImplicitBoolCast'
1>          c:\qt\4.8.4\include\qtcore\../../src/corelib/tools/qstring.h(62) : see declaration of 'QString'
1>
1>Build FAILED.

my code is like this:

#include <QtCore/QCoreApplication>
#include <QString>
#include <Qt3Support>


#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString b;

    std::cout << "B" << b<<"\n";

    return a.exec();
}

the error info is always assicaited with the use of QString

std::cout << "B" << b<<"\n";

I googled the error but find some info about proting qt3 coe to qt4, they say i should add QT3_SUPPORT, include , I do this, but still have this erro , so I am confused and have no solution to cope with this error.

Was it helpful?

Solution

There is no << operator for basic_ostream (std::cout) and QString.

But there is a class that can encapsulate std::cout for the use with Qt:

QTextStream cout(stdout);
cout << "B" << b << "\n";

Another way would be to explicitly cast it to char*:

std::cout << "B" << b.toLocal8Bit().data() << "\n";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top