Important: Please read the Qt Code of Conduct -

PDF issue with Qt

  • I'm trying to add a Pdf file to a widget (using ActiveX).

    When running axwidget is added but does not show the controls AdobeReader (AcroPDF.PDF) and also does not show the pages of the Pdf file, is just a gray widget.

    My code:

    @ #include "mainwindow.h"
    #include "ui_mainwindow.h"

    #include <QAxWidget>
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        QAxWidget *pdfWidget = new QAxWidget;
        pdfWidget->resize(740, 580);
        pdfWidget->dynamicCall("LoadFile&#40; const string& &#41;", "http://localhost/order.pdf"&#41;;
        delete ui;

    What have I done wrong?

  • The function prototype (first argument) given to dynamicCall() is missing its closing parentheses. Whether that is the only problem...

  • Moderators

    The parentheses is missing but that's not the main problem. The thing is acrobat ocx can't load content from a http url. You need to download the file first (eg. via QNetworkAccessManager), store it somewhere(eg. via QTemporaryFile) and use the local url for the LoadFile.

  • ChrisW67 it was a failure of "Qt-project" at the time I posted the code. I edit the question.

    ChrisKawa I was doing this:

    @ QAxWidget *pdfWidget = new QAxWidget;
    pdfWidget->resize(740, 580);

    But I could not send Session/Cookies/Headers on it and not the SWF/PDF files:

    I'm trying to implement plugins in QWebView.

    The problem is that pages that use sessions/cookie/POST method to display a file (such as PDF or SWF in my case) do not receive this information.

    How do I send sessions/cookie/POST method in QWebPluginFactory::create ?


    @QObject *PluginsFactory::create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
    if (mimeType == "application/pdf") {
    QAxWidget *pdfWidget = new QAxWidget;
    qDebug() << "Please install Adobe Acrobat Reader (R) for Pdf support!";
    } else {
    pdfWidget->setProperty("src", url.url());
    return pdfWidget;

    if (mimeType == "application/swf") {
    QAxWidget *flash = new QAxWidget;
    flash->resize(740, 580);
    qDebug() << "Adobe Flash Player (R) for SWF support!";
    } else {
    flash->dynamicCall("LoadMovie(long,string)", 0, url.url());
    return flash;
    return 0;

  • Moderators

    Why do you implement plugins on your own? QWebView already supports plugins for flash, pdf(if any reader is available) etc.
    They are disabled by default but can be easily turned on:
    webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);

  • Chris Kawa, there is a bug in QT5, see:

    When I used "QWebPluginFactory::create" the BUG stopped. So we want to use "QWebPluginFactory::create".

    How can I use ActiveX with QNetWorkAccessManager?

  • bq. How can I use ActiveX with QNetWorkAccessManager?

    Fetch the remote file into a local temporary file with QNetworkAccessManager, QNetworkRequest and QNetworkReply. See the "Network Download Example" in the Qt docs.
    Pass LoadFile() the path to the temporary file.

  • bq. Pass LoadFile() the path to the temporary file.

    But if a SWF comes from the C:\windows\temp, the SWF will not be able to access pages "http" because it violate the Flash restrictions, Am I right?

  • Moderators

    The downloading was only for pdfs (the acrobat reader ocx to be exact). Other plugins I don't know. I would imagine flash component can handle http.

    To be honest it's a lot of work to properly handle all possible plugins with all their quirks and webkit guys already did it. I would put my efforts into fixing the issue with QWebView support of plugins that you've mentioned than reinventing the wheel.

  • bq. I would put my efforts into fixing the issue with QWebView support of plugins that you’ve mentioned than reinventing the wheel.

    I fully agree.

    But what if I use new plugins there must be a way to maintain the link between NetWorkAccessManager and plugins.

    I believe my code is using QAxWidget inappropriately, maybe I should use QAxClientSite (or something that has nothing to do with it), but I have some experience with this situation.

Log in to reply