qtqwebpage

Why nothing is display when I use QWebpage


it's very stupid question but I don't understand why nothing is display in my qt console application when I use QWebpage :

This is my basic code :

#include <QCoreApplication>
#include <QtWebKitWidgets>
#include <QDebug>
#include <stdio.h>
#include <iostream>

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

    /*QWebPage page;
    page.settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
    page.settings()->setAttribute(QWebSettings::AutoLoadImages, true);
    page.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    page.settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
    page.settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    page.mainFrame()->load(QUrl("http://myflowerpower.parrot.com/#plantdb/3"));
    qDebug () << "source html : \n";
    qDebug() << page.currentFrame()->toHtml();
    QString htmlResult = page.currentFrame()->toHtml();*/

    printf("test");
    std::cout << "test std::cout\n";
    qDebug() << "Debug Message";
    qWarning() << "Warning Message";
    qCritical() << "Critical Error Message";
    bool result = a.exec();

    return result;
}

If I uncomment the code, nothing is display, but if I comment QWebpage stuff it's work without problem. Have any idea ?


Solution

  • QCoreApplication can't handle GUI elements.

    You need to use QApplication instead to support the GUI and the event framework.

    And make sure that you have what is needed in your .pro file.

    QT += widgets webkitwidgets
    

    Hope that helps.