How to print Qdate value on screen

  • Hello, I am very new to Qt and I bumped into a problem that might well be stupid as far as I know. In the following chunk of code

    QFile file("bds.txt");
    QTextStream in(&file);
    if (! | QIODevice::Text))
           return 1;
    QString discard,dateStr;
    QList<QDate> dates;
        in >> discard;
        in >> dateStr;
    QString dt ((dates[0]).toString());
    std::cout << dt << std::endl;

    I obtain the following error

        error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'QString') std::cout << dt << std::endl;

    So I created a TextStream as follows

    QTextStream outt(stdout);
    outt << dt << std::endl;

    Obtaining the following error

    error: no match for 'operator<<' (operand types are 'QTextStream' and '<unresolved overloaded function type>') outt << dt << std::endl;

    How can I overcome this problem and why am I having this problem in first place?

  • I think this one should work:

    std::cout << dt.toStdString() << std::endl;

  • Moderators

    @RDiGuida To add to @Mario84's answer, QString is Qt based class and your using standard c++ API's to print it which it doesnot understand. To print values of pure Qt based API's you can use qDebug().

    QString dt ((dates[0]).toString());
    qDebug() << dt;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.