QT5 qDebug()<<QByteArray empty



  • i have a problem,i try get html use QNetworkAccessManager from a url.statusCode is 200,debug reply->readAll() hava data,length is 35988,but use qDebug() print it's empty,nothing,im environment windown7 x32 chinese +qt5.5 x32(mingw),copy code to linux(qt5.5 x64),it's ok,can print html content,why?please help me ,thanks.my code like this:

    QEventLoop loop;
    QTimer timer;
    QNetworkRequest request;
    request.setUrl(QUrl("http://mp.weixin.qq.com/s?__biz=MzA4MjAzMzg4NA==&mid=208317469&idx=4&sn=0928285db7c368e276e85519b3d0763b&3rd=MzA3MDU4NTYzMw==&scene=6#rd"));
    request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" );
    request.setRawHeader("Accept-Language", "zh-CN,zh;q=0.8");
    request.setRawHeader("Accept-Encoding", "none");
    request.setRawHeader("Accept-Charset", "utf-8");
    request.setRawHeader("Connection", "keep-alive");
    request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8");
    QNetworkReply *reply = manager->get(request);
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(timeout);//超时10秒
    loop.exec();
    if(reply->error()){
    qDebug()<<"error";
    }
    QByteArray res= reply->readAll();
    reply->close();
    reply->deleteLater();
    // QString str = QString::fromUtf8(res.data(), res.size());
    qDebug()<<statusCode;
    qDebug()<<res;



  • I'm no sure, but i think problem in using '<<' operator, since Qt 5.5 Win. Try to use qDebug(res.constData()) instead.
    I have problem too with qDebug() on Qt 5.5. When i try something like:
    QString str = 'Проверка'; // Russian
    qDebug() << str;
    in messageHandler i get msg = '\u0422\u0435\u0441\u0442' and i can't solve this problem.
    But if qDebug() << 'Проверка' or qDebug(str.toLocal8Bit().data()) is all fine.


  • Moderators

    Couple of things might be going on here...

    1. If you are running your application on the console and expecting so see output you need to make sure you have CONFIG += console in your pro file. This only seems to affect windows applications, which is why linux works fine and windows doesn't print anything.

    2. Make sure you have Qt Debugging enabled. In linux for me I have to turn off Qt debugging while using plasma5 as it outputs way way too much to /var/log/messages. So I do export QT_LOGGING_RULES="*.debug=false" This turns off the ability to see qDebug() messages in my own apps as well. SO I have to unset QT_LOGGING_RULES to see my messages. So make sure in windows you don't have any QT_LOGGING_RULES environment variables set.

    My guess would be #1. :) Mainly because that has happened to me a number of times when I forget to add the console to config.


Log in to reply
 

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