Problem with LIbrary: how to configure QtWebKit to parse HTML?

Nick Presta showed that you can parse HTML with qt here: https://stackoverflow.com/questions/489522/library-recommendation-c-html-parser

However, when I try to create this, I get an access violation on "QWebFrame * frame = page.mainFrame ();" line.

What am I doing wrong?

#include <QtWebKit\QWebElement>
#include <QtWebKit\QWebView>
#include <QtWebKit\QWebFrame>
#include <QtWebKit\QWebPage>
#include <iostream>

int main() {
 QWebPage page;
 QWebFrame* frame = page.mainFrame();

 frame->setHtml( "<html><head></head><body></body></html>" );
 QWebElement document = frame->documentElement();

 return 0;
}
+3
source share
2 answers

You often need QApplication(for the GUI, for others to use QCoreApplicaiton) an object before doing anything useful in Qt.

Try declaring one at the top of main:

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

    ...

    return a.exec(); // start event handling (if you have some UI or networking that is event based)
}

a.exec() 0 ( ) , , . , .

OTOH, WebKit exec - , .

+2

Qt, , , :

QString text = plainTextEdit->toPlainText();
webView->setHtml(text, baseUrl);
+1

Source: https://habr.com/ru/post/1783319/


All Articles