QHelpEngine how-to
Page |
1 |
Hello, I’m trying to make a simple off-line help for my application. I want to make something of general so I’m trying to lay on QtHelp framework.
I met the QHelpEngine class but relative reference documentation is very poor and I didn’t find any how-to. So, following model/viewer programming and after I put help.qhc file in resources directory I did something like this:
- splitter->addWidget(contentWidget);
- splitter->addWidget(indexWidget);
- contentWidget->setModel(contentModel);
- indexWidget->setModel(indexModel);
- splitter->show();
but it shows a empty index and a empty content.
Application has no advice output.
Where I did wrong?
Please help me.
Best Regards
Willy
20 replies
Does it work with the docs on the hard disk?
Did you add the file to the .qrc configuration file?
Are the files present in the resources? You can use QDir on file path “:/” to look at the contents.
It doesn’t work with docs on the hard disk because I tried to add the absolute path of .qhc file (for example: QHelpEngine(”/home/willy/help.qhc”)) and it doesn’t work.
I added it to .qrc configuration file and the file is present in the resources.
I don’t understand why I have to use QDir.
This is the help.qhp file:
- <?xml version="1.0" encoding="UTF-8"?>
- <QtHelpProject version="1.0">
- <namespace>wchords-client</namespace>
- <virtualFolder>help</virtualFolder>
- <customFilter name="wchords-client">
- <filterAttribute>wchords-client</filterAttribute>
- <filterAttribute>all</filterAttribute>
- </customFilter>
- <filterSection>
- <filterAttribute>wchords-client</filterAttribute>
- <filterAttribute>all</filterAttribute>
- <toc>
- <section title="WChords-client Manual" ref="description.html">
- <section title="Import Tool" ref="import_tool.html" />
- </section>
- </toc>
- <keywords>
- <keyword name="import" id="wchords-client::import" ref="import_tool.html" />
- <keyword name="description" id="wchords-client::description" ref="description.html" />
- </keywords>
- <files>
- <file>*.html</file>
- <file>images/*.jpg</file>
- </files>
- </filterSection>
- </QtHelpProject>
It seems correct for me…
Ok I have put all in a zip file containing my help system. It’s very small and available at http://dl.dropbox.com/u/7070214/WChords/related_files/help_files.zip
I did
- qcollectiongenerator help.qhcp -o help.qhc
to generate help collection.
Ok, two things:
First: you must call
- he->setupData();
before you can use the help data. It returns a bool if the setup was ok. Use QHelpEngineCore::error() [doc.qt.nokia.com] to retrieve an error message (QHelpEngine dervives from QHelpEngineCore).
Second, the more important part: You cannot use Qt resources for storing the help content. You must put it into regular files and distribute them along your application.
The reason for the latter is simple: The compiled help files are actually SQLite databases. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.
It doesn’t work anyway and error() leaves no error. This is the new code:
- he->setupData();
- qDebug() << he->error();
- splitter->addWidget(contentWidget);
- splitter->addWidget(indexWidget);
- contentWidget->setModel(contentModel);
- indexWidget->setModel(indexModel);
- splitter->show();
I took care to call program in the same help.qhc directory.
I followed your suggest and this is the new code:
- if (fileInfo.exists()) {
- he->setupData();
- qDebug() << fileInfo.absoluteFilePath();
- qDebug() << he->error();
- splitter->addWidget(contentWidget);
- splitter->addWidget(indexWidget);
- contentWidget->setModel(contentModel);
- indexWidget->setModel(indexModel);
- splitter->show();
- }else{
- qDebug() << "File doesn't exist";
- }
It outputs the correct absolute file name(see line 6) and there is no error.
But it doesn’t work….
You must log in to post a reply. Not a member yet? Register here!



