Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to print Qdate value on screen

How to print Qdate value on screen

Scheduled Pinned Locked Moved General and Desktop
stringqdatestdoutscreen
3 Posts 3 Posters 5.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RDiGuida
    wrote on 13 Apr 2015, 11:19 last edited by
    #1

    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 (!file.open(QIODevice::ReadOnly | QIODevice::Text))
           return 1;
    
    QString discard,dateStr;
    QList<QDate> dates;
    
    while(!in.atEnd())
    {
        in >> discard;
        in >> dateStr;
        dates.append(QDate::fromString(dateStr,"d'/'MMM'/'yyyy"));
    }
    
    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?

    P 1 Reply Last reply 13 Apr 2015, 11:38
    0
    • M Offline
      M Offline
      Mario84
      wrote on 13 Apr 2015, 11:29 last edited by
      #2

      I think this one should work:

      std::cout << dt.toStdString() << std::endl;
      
      1 Reply Last reply
      1
      • R RDiGuida
        13 Apr 2015, 11:19

        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 (!file.open(QIODevice::ReadOnly | QIODevice::Text))
               return 1;
        
        QString discard,dateStr;
        QList<QDate> dates;
        
        while(!in.atEnd())
        {
            in >> discard;
            in >> dateStr;
            dates.append(QDate::fromString(dateStr,"d'/'MMM'/'yyyy"));
        }
        
        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?

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 13 Apr 2015, 11:38 last edited by
        #3

        @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().
        Eg:

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

        157

        1 Reply Last reply
        1

        1/3

        13 Apr 2015, 11:19

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved