Instantiating QWebPage prevents my application from starting
-
Hello Everyone,
I wanted to generate a pdf from an HTML string.
So I downloaded QtWebKit and QtWebKitWidgets binaries and copied them to my Qt directory in their respective folders.
I also used mklink (as I am running on windows 10) to generate symbolic links for running the application in debug mode.However , when I try to create a QWebPage object , the application crashes upon start.
My environment :
Qt Creator : 4.14
Kit : Desktop Qt 15.13.0 MinGW 64 bit
OS : Windows 10 x64project file configurations :
QT += core gui printsupport sql webkit webkitwidgets
Includes :
#include "pdfcreator.h" #include <QFile> #include <QTextStream> #include <QTextDocument> #include <QPdfWriter> #include <QtPrintSupport/QPrinter> #include <QtWebKit> #include <QtWebKitWidgets> #include <QWebPage>
the part of code causing the problem :
QString html = OpenHtml+CSS+OpenBody+LogoImage+InvoiceInfo+TableHeader+InvoiceBody+EndTable+TotalsSection+CloseBody+CloseHtml; QWebPage *newPage = new QWebPage(this); QPrinter printer(QPrinter::PrinterResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(QPrinter::A4); printer.setOutputFileName("Invoice.pdf"); printer.setPageMargins(QMarginsF(15, 15, 15, 15)); newPage->mainFrame()->setHtml(html); newPage->mainFrame()->print(&printer);
If I comment that part out , the application starts normally.
I tried it in debug and release modes and I get the same error.error in Debug mode:
22:01:25: Debugging starts 22:01:28: Debugging has finished
error in release mode :
22:21:36: Starting D:\MyWork\EInvoice\centuria.einvoice.21\build-Einvoice-Desktop_Qt_5_13_0_MinGW_64_bit-Release\release\Einvoice.exe ... 22:21:38: The program has unexpectedly finished. 22:21:38: The process was ended forcefully. 22:21:38: D:\MyWork\EInvoice\centuria.einvoice.21\build-Einvoice-Desktop_Qt_5_13_0_MinGW_64_bit-Release\release\Einvoice.exe crashed.
Can you please help me with that ?
Thanks a lot . -
Hi and welcome to devnet,
Are you sure that the "mainFrame" returned value is not a nullptr ?
On a side note, QtWebKit has been deprecated and remove from the officially supported modules since 5.6. Where did you get the module from ?
-
-
@Marco4ever7
then probably you are just missing some dependency libraries (or incompatible version)?
Use DependencyWalker and drag your exe/dll file into it and see if all libs could be found. -
@raven-worx I used the dependency walker , but it showed that there are hundreds of missing dependencies , and it showed the same when I ran it on a working application .
they were all starting with "API_MS_*".
Is there something more specific I should look into ? -
@Marco4ever7
ignore those.
just check the first level of the dependency tree. -
You should use the debugger to get more information about the crash.
-
@SGaist I did , and it is not even starting , it crashes just after starting(see the error log in the topic description).
@raven-worx I am sorry but I never used the dependency walker , where should I be looking ?
-
Looks like the Qt version you are using is different than the one that was used to build QtWebKit.
By the way, why not use QtWebEngine ?
-
@Marco4ever7
yes you are on the right track. Your Qt5Core.dll doesnt match for some reason.
See https://www.dependencywalker.com/help/html/hidr_module_list_view.htmSeems the error is the exported symbol
QtPrivate::argToQString(QStringView)
. QStringView was added in Qt 5.10.
I have no idea against what version QtWebkit was built against. Maybe Qt 5.6 (?) since this was the last version it was included.Normally this should be ensured under the terms of binary backward compatibility. But i assume QtWebKit is using some private classes for which binary compatibility isn't ensured.
In the worst case you will have to build the QtWebKit module yourself against your Qt version.
By the way, why not use QtWebEngine ?
i think because of mingw
-
@raven-worx said in Instantiating QWebPage prevents my application from starting:
@Marco4ever7
yes you are on the right track. Your Qt5Core.dll doesnt match for some reason.
See https://www.dependencywalker.com/help/html/hidr_module_list_view.htmSeems the error is the exported symbol
QtPrivate::argToQString(QStringView)
. QStringView was added in Qt 5.10.
I have no idea against what version QtWebkit was built against. Maybe Qt 5.6 (?) since this was the last version it was included.By the way, why not use QtWebEngine ?
i think because of mingw
@SGaist @raven-worx yes , precisely . I know it would have saved me a lot of trouble if I could use QWebEngine , but unfortunately I can't.
So I think I will attempt to build the QtWebKit on my machine and get back to you .
Thanks a lot for the help guys \m/P.S : If there is a reference on how to build the QtWebkit , that would be so helpful.
-
This post is deleted!
-
@SGaist @raven-worx I tried to build QtWebkit but unfortunately it failed because of some remote repo has been taken offline .
I think I will explore another option .
Thank you guys or the help. -
@Marco4ever7 You can download mingw binaries for Qt 5.14.1 from https://github.com/qtwebkit/qtwebkit/releases/tag/qtwebkit-5.212.0-alpha4
-
@Konstantin-Tokarev Thank you for the link . But I already solved my problem with QTextCursor and QTextDocument sice I only needed to print to a PDF ,also I am working on Qt 5.13.0 so I don't want to mess with my environment as I am still kind of a noob xD and I hate environment -related issues . But thanks a lot though .