Displaying help through QtHelp using QWebView



  • Hi all

    This is what i'm trying to achieve: I've made a helpcollection-file with some html-content files in it. I want to display this pages in a QWebView.
    I can display the pages, but my images and css I added aren't displayed.

    I used QWebInspector to see if my content is loaded, but i can't really make sense out of it.
    !http://wouterverbruggen.be/img/outcome.jpg(Outcome)!
    The example I used here, has to be a table with borders, but as you can see, no borders are shown (doc has to be the collectionfile I loaded, I think)

    Code behind it:
    @QString myHtmlContent = QString(m_helpEngine->fileData(url));
    QUrl myBaseUrl = QUrl("qthelp://com.mynamespace/doc");
    if(!myHtmlContent.isEmpty())
    {
    ui->webView->setHtml(myHtmlContent, myBaseUrl);
    }

    ui->webView->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    QWebInspector *inspector = new QWebInspector(ui->webView);
    inspector->setPage(ui->webView->page());
    inspector->setFixedSize(HelperWindow::width(), 400);
    inspector->setVisible(true);@
    

    Is there maybe anybody who knows more about this topic? And willing to help me achieve this thing.

    Thanks in Advance

    PS: If this topic isn't in the right forum, please say so, thanks.



  • bq. (doc has to be the collectionfile I loaded, I think)

    The problem is in the HTML you are setting! Is it correct and consistent? Does it pass w3c HTML-check?

    Post it here if you need further help.



  • Thanks for your reply, I checked, made the changes, but it didn't help.

    I got the css-problem solved by program it in the head-tag of my document. But the images are a pain in the ass. Seems like I can't add 'external files' to the webview.
    Although I specified them in my qhp-file



  • You should use file:// url for img src with full path, or you can pack all images in qrc and use them from there with ":/" link schema.

    you can generate dynamic full path by replacing place holders in your html. for example:
    @
    QString html = "<html><body><img src = "%FULLPATH%"/test.png /> <br> <img src = "%FULLPATH%"/test2.png /></body></html>";
    html.replace(QString("%FULLPATH%"),qApp().arguments().at(0));

    view->setHtml(html);
    @



  • So actually the images aren't 'stored' in my qhc-file? Even though I add them in my qhp-file.

    Well that's a pitty.
    If I use file://, do I have to put the whole path in? C:/myapplication/doc/images/... or am I wrong here?



  • bq. use file:// url for img src with full path

    What's right, full path. I didn't ever have used qhp, so maybe where is another way... I don't know.
    Another option is to use images directly included in html source, like this:

    @<img src="data:image/gif;base64,R0lGODlhQAA4APcAAOq/GfLy8v711PPWY+rUmOjo6PT09Ozs7OvduP3RWsnJyezn2urq6sO1jqWl
    pf3yw/HNPdfW1uLi4sbGxo97R+/JMbq6uu3FKfnmldnW0frsxPnx2d7e3qmpqdzc3PDMOfromaGh
    ocWzfezCIdDQ0MHAwPXdfq6urvnmmPnjjfXgie7u7ubm5vLRRfHPQPLu5vzrvbW1teDg4NrWzPfh
    gvrPWPXabbGxsfXdee/KNOTk5Nra2vnz4ejew/vsqfrpqf3xvujXq/nlk+m7EPnnnNa8db6+vvbc
    dfztrvPx7czMzM/OzvnppPXYau7TiuzIafHQUfPUWaejmvPVXu3EJvrolu7GLNTU1PronLy8vOri
    zfTYZPzbdvPXafvcgvXacfjhhvzxufnQS+vBH+vAHbelcvLSVfzvsum8E/TGM/3vtvvrovDLN//o
    q/7lmq2cavXeg/vspf7xzem8EvPSSNPS0v3oou7KPf71zfTbdPvurei6DvnopvbJOvHSWPjnoLi4
    uNjY2Pvqpfb18f3nnvjt0f7movzwtvrhn/bccvronvnooPnST/nhofnoovXSS8GveOzDJJqIWfTU
    TfvroPr16dnY1eq+F97NkfLQQvrpovjon+vBIP30yO7ILvHho/bij9C3X/vqn/rpn/zSUtTDiHxq
    QfDQT/7+/mlWMv39/f/RVPHx8fz8/Pr6+vj4+Pv7+/f39/n5+fb29p+fn/Dw8OHh4dTT09bV1em9
    Fd3d3ePj4+Lh4vDLOOq/G8/Pz+q9FsvLy+Xl5fvtqu3t7fPZcNHR0fPYbefn5/DLQO/MRP3srdC4
    Ybe3t/3jn/r5+e/s4/vTYPTMX+np6ffmufnmtOvr6+zr7Nvb29/f38PDw/fffqaloP7opvvYaqur
    q/39/PnVVbu7u8a/rvjjkPfMQv7ll/jjrPTbd/zomvrYePnbivXTWuXGcs3Nzdva2vPYZ/X19d3c
    3PfSTf7yyNrZ2fnelPTQRvTRUvTVUfzur/7rsf/rtvD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L29761gjGyGgAZsFRgVRzFthcwQGmUQAWCEMHu5CALWSQLA5YVxfY1YUHtstd7mY3
    Q9ZNlgxsIQEJ6EAYLCjANDI6z1nI4p7+MaRsX2mAANRiBcQ4AAOYiwzn6uC/7CmvdDdF4E3ZgrwS
    YM8u/ote4kyDAQcgBmECYIBZQPOeBQmjK18Ri3jU17735c0BrDFiBux3v9NIsYpTbOIWX4PEvKFM
    LVhB4VnE4hWyQKUgERLGQyayIxyeRTyG3JW0GJkVSE6ykpFsZAp3pcI2xrEsopnKQT5kkPJFJCwS
    6Youu0IWUkYJh8VMZilP2RXP6PKWUZlKVa7yGSJYFqQY5zxncIgxlW0+ZJ7nvGcs47MhAQEAOw==" />
    @



  • I think i will go for the qrc-declaration :D If I use this method, I don't need to put the images in the file collection?
    Damn this is hard to program, and there isn't a solution online.



  • bq. images in the file collection?

    I didn't get it... what do you exactly mean?
    if you put all images in qrc, they will be compiled in .DATA section of your executable.
    You can also create second project for Qt Dynamic Library and put all your images where in qrc file. And in your main Project you can then load this library as resource library with "QResource":http://doc-snapshot.qt-project.org/4.8/qresource.html and use all your resources from this library. It's main approach for separating resources and executive code... You can even compress resources in this library to save a place...



  • Here is main info about "Qt Resource System":http://qt-project.org/doc/qt-4.8/resources.html



  • You have Qt Help Project (.qhp) with content like this:
    @<?xml version="1.0" encoding="UTF-8"?>
    <QtHelpProject version="1.0">
    <namespace>mycompany.com.myapplication.1.0</namespace>
    <virtualFolder>doc</virtualFolder>
    <customFilter name="My Application 1.0">
    <filterAttribute>myapp</filterAttribute>
    <filterAttribute>1.0</filterAttribute>
    </customFilter>
    <filterSection>
    <filterAttribute>myapp</filterAttribute>
    <filterAttribute>1.0</filterAttribute>
    <toc>
    <section title="My Application Manual" ref="index.html">
    <section title="Chapter 1" ref="doc.html#chapter1"/>
    <section title="Chapter 2" ref="doc.html#chapter2"/>
    <section title="Chapter 3" ref="doc.html#chapter3"/>
    </section>
    </toc>
    <keywords>
    <keyword name="foo" id="MyApplication::foo" ref="doc.html#foo"/>
    <keyword name="bar" ref="doc.html#bar"/>
    <keyword id="MyApplication::foobar" ref="doc.html#foobar"/>
    </keywords>
    <files>
    <file>classic.css</file>
    <file>*.html</file>
    </files>
    </filterSection>
    </QtHelpProject>@

    And in the <files>-section you have to add the links of the images you use for displaying them in QAssistant (So I presume you need them too to display them in your QWebView).

    But what I am trying now is to put my Qt Compressed Help (.qch) and Qt Help Collection (.qhc) in a resource file, so I can just call them in my application using QAssistant:
    @assistant -collectionFile :/help/helpcollection@

    bq. The collection file ':help/helpcollection' does not exist...

    Doesn't seem to work. Although everything is properly coded:
    @<RCC>
    <qresource prefix="/help">
    <file alias="helpcollection">doc/mycollection.qhc</file>
    <file alias="compressedhelp">doc/mycollection.qch</file>
    </qresource>
    </RCC>@

    I'm struggling for days now, really want to throw out my pc :o



  • Can't get it fixed. Why aren't my images loaded trough my helpcollection file? I can't imagine Qt Assistant uses this way to display images. It has to be in the collection file.



  • This seems to have done the trick for me. Manually splitting the qt url and converting from the help namespace to the regular file system. Phew!

    @
    class HelpBrowser(QWebView):
    def init(self, helpEngine, parent=None):
    QWebView.init(self, parent)
    self.helpEngine = helpEngine

    def load(self, url):
        import os
        if (url.scheme() == "qthelp"):
            path = QFileInfo(self.helpEngine.collectionFile&#40;&#41;&#41;.path()
            fileName = QFileInfo(url.toString()).fileName()
            url = QUrl.fromLocalFile&#40; os.path.join(str(path&#41;, str(fileName&#41;))
        QWebView.load(self, url)
    

    @


Log in to reply
 

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