Openning PDF in QML (or running an external application)



  • Hi, I'm working on an application for Embedded Linux (RaspPi, to be exact), but currently I'm compiling it for Windows, so I can have a "proof_of_concept" app. One of the features of the app should be working with (or at least rendering properly) container files (e.g PDF, DJVU). Obviously there is no obvious (well, at least for me) way to open and work with those in qml. One solution would be to run an external app, like Adobe Reader (not the best solution, but after all the trouble I went through, it's seems ok with me), but I can't seem to do even that. I probably made some stupid mistake, but I still haven't caught it yet.

    Here is my shell.h:

    @#ifndef SHELL_H
    #define SHELL_H

    #include <QObject>
    #include <QProcess>

    class Shell: public QObject
    {
    Q_OBJECT
    public:
    explicit Shell(QObject *parent = 0);
    ~Shell();
    Q_INVOKABLE void launch(const QString &program);

    protected:
    QProcess *m_process;

    };

    #endif // SHELL_H@

    Here is shell.cpp:

    @#include "shell.h"
    #include <QProcess>

    Shell::Shell(QObject *parent) :
    QObject(parent),
    m_process(new QProcess(this))
    {

    }

    void Shell::launch(const QString &program)
    {
    m_process->start(program);
    m_process->waitForFinished(-1);

    }

    Shell::~Shell() {

    }@

    Here is the line in main.cpp with witch I added shell to qml:

    @qmlRegisterType<QObject>("Shell", 1, 0, "Shell");@

    And here is the qml, which is loaded via Loader item:

    @import QtQuick 2.2
    import Shell 1.0

    Rectangle{
    Component.onCompleted: qprocess.launch("some_totaly_accurate_path_to_an_exe_application")
    Shell{
    id: qprocess
    }
    }@

    Aside from not launching app and giving me: TypeError: Property 'launch' of object QObject(0x4202448) is not a function
    everything else seems to be ok.

    So my questions are:
    1)What is the problem with the code, and how can it be improved.
    2)Would this code be any different on RaspPi (for example, would I be able to work with somthing like "xpdf name_of_my_pdf_file.pdf", or should the code be tweaked)

    1. But the major question is: are there any alternatives? Actualy I'm not restricted to pdf or anything like it. I just need a file that can be like an ebook(have markup, images and so on), so basicly html would also do the trick, but I don't think QWebView would work on embeded linux, and Rich Text is not quite that( no easy way to have images nearby). So any suggestions? Thanks in advance, an sorry for English.

  • Moderators

    You have 2 systems that are built into Qt and guaranteed to work on supported platforms:

    You can feed those methods basically anything, and it will be opened by the native app for a given file, or the web browser.



  • [quote author="sierdzio" date="1404586826"]You have 2 systems that are built into Qt and guaranteed to work on supported platforms:

    You can feed those methods basically anything, and it will be opened by the native app for a given file, or the web browser.[/quote]

    Thank you, openUrlExternally() is a life saver (though I can't seem to make it work either, but nothing I would not be able to handle myself :) )

    Still, I'm curious about the 3rd question. Basicly, what I want, is a ebook reader with images and interactivity. Openning a file in an external program is the most easy and obvious one, but not elegant, and I might have problems with application owners. Since it is a project that is thought out and made entirely by me for schools and educational purposes, I have freedom to chose which format will be used for books, therefore I'm looking towards HTML (or XML) but I can't think of a way to work with those on embeded linux (that doesn't mean that that is imposible). I would be happy if someone would give me a hint on what shoud i do in this situation



  • Hi Darkmalex,
    I suggest you to use the Poppler lib to open and view PDF documents.



  • [quote author="aabc" date="1404632512"]Hi Darkmalex,
    I suggest you to use the Poppler lib to open and view PDF documents. [/quote]

    Thanks. Might give it another try, because my previous attempts to work with poppler were not that good, but it still seems like the only option I have left to embed books into my app.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.