H
H
Hello America2014-05-30 20:14:16
Qt
Hello America, 2014-05-30 20:14:16

QWebView - how to load a page from html code (Qt)?

Failed to load:

//---------Scripts-----------
    QString textScript ="<script>alert('Hello!');</script>";

    //---------Styles------------
    QString textStyle="<style>#title{font-size:20px;background-color:red;text-align:center;}</style>";

    QString startText = "<html><head>"+textStyle+textScript+"</head><body><div id='title'>Hello!</div><br/>";
    QString endText = "</body></html>";

    QUrl baseUrl = QUrl::fromLocalFile( QDir::current().absoluteFilePath("mybinaryfile") );

    QString htmlText = startText + " " + endText;

    ui->webView->setHtml(htmlText, baseUrl);//Что за второй параметр?

What to pass to setHtml(htmlText, baseUrl); in the second parameter? I found this code, but it swears and displays an error:
C:\Qt\Tools\QtCreator\bin\Formula\mainwindow.cpp:154: ошибка: incomplete type 'QDir' used in nested name specifier
     QUrl baseUrl = QUrl::fromLocalFile( QDir::current().absoluteFilePath("mybinaryfile") );
                                         ^

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hello America, 2014-05-30
@websofter

The problem was solved by adding a line
to the project file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question