February 21, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

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:

  1.     QHelpEngine* he = new QHelpEngine(":help/help.qhc");
  2.  
  3.     QHelpContentModel *contentModel = he->contentModel();
  4.     QHelpContentWidget *contentWidget = he->contentWidget();
  5.     QHelpIndexModel* indexModel = he->indexModel();
  6.     QHelpIndexWidget* indexWidget = he->indexWidget();
  7.  
  8.     QSplitter* splitter = new QSplitter();
  9.     splitter->addWidget(contentWidget);
  10.     splitter->addWidget(indexWidget);
  11.  
  12.     contentWidget->setModel(contentModel);
  13.     indexWidget->setModel(indexModel);
  14.  
  15.     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

21 replies

February 21, 2011

Volker Volker
Ant Farmer
5428 posts

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.

February 21, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

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.

February 21, 2011

Volker Volker
Ant Farmer
5428 posts

You can use QDir to list the bundled resources (are all expected files in there, etc.). It does not help in using the help engine, though.

Does your help collection work with Qt Assistant? You can test it by adding “-collectionFile xxx” on the command line.

February 21, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

Strange, If I add collection file by Preferences panel of Qt Assistant I see it, but if I use -collectionFile command line option I don’t see it…

February 21, 2011

Volker Volker
Ant Farmer
5428 posts

It works for me, but only if I add data to the keywords and toc sections in the XML configuration file.

February 21, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

This is the help.qhp file:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  <QtHelpProject version="1.0">
  3.      <namespace>wchords-client</namespace>
  4.      <virtualFolder>help</virtualFolder>
  5.      <customFilter name="wchords-client">
  6.          <filterAttribute>wchords-client</filterAttribute>
  7.          <filterAttribute>all</filterAttribute>
  8.      </customFilter>
  9.      <filterSection>
  10.          <filterAttribute>wchords-client</filterAttribute>
  11.          <filterAttribute>all</filterAttribute>
  12.          <toc>
  13.              <section title="WChords-client Manual" ref="description.html">
  14.                  <section title="Import Tool" ref="import_tool.html" />
  15.              </section>
  16.          </toc>
  17.          <keywords>
  18.              <keyword name="import" id="wchords-client::import" ref="import_tool.html" />
  19.              <keyword name="description" id="wchords-client::description" ref="description.html" />
  20.          </keywords>
  21.          <files>
  22.              <file>*.html</file>
  23.              <file>images/*.jpg</file>
  24.          </files>
  25.      </filterSection>
  26.  </QtHelpProject>

It seems correct for me…

February 21, 2011

Volker Volker
Ant Farmer
5428 posts

The file looks ok to me (though I’m not an expert in creating help content).

Can you put together a small sample, just two or three help files, the config files etc. and put a ZIP on pastbin ore something similar. We can have a look then.

February 22, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

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

  1. qcollectiongenerator help.qhcp -o help.qhc

to generate help collection.

February 22, 2011

Volker Volker
Ant Farmer
5428 posts

Just tried it on the command line, everything is fine:

  1. /Applications/Assistant.app/Contents/MacOS/Assistant -collectionFile help.qhc

February 23, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

Yes it works to me too. But why it doesn’t work with this code?

  1. QHelpEngine* he = new QHelpEngine(":help/help.qhc");
  2.  
  3. QHelpContentModel *contentModel = he->contentModel();
  4. QHelpContentWidget *contentWidget = he->contentWidget();
  5. QHelpIndexModel* indexModel = he->indexModel();
  6. QHelpIndexWidget* indexWidget = he->indexWidget();
  7.  
  8. QSplitter* splitter = new QSplitter();
  9. splitter->addWidget(contentWidget);
  10. splitter->addWidget(indexWidget);
  11.  
  12. contentWidget->setModel(contentModel);
  13. indexWidget->setModel(indexModel);
  14.  
  15. splitter->show();

Maybe I got wrong in something…

February 23, 2011

Volker Volker
Ant Farmer
5428 posts

Ok, two things:

First: you must call

  1. 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.

February 24, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

It doesn’t work anyway and error() leaves no error. This is the new code:

  1.     QHelpEngine* he = new QHelpEngine("./help.qhc");
  2.     he->setupData();
  3.     qDebug() << he->error();
  4.  
  5.     QHelpContentModel *contentModel = he->contentModel();
  6.     QHelpContentWidget *contentWidget = he->contentWidget();
  7.     QHelpIndexModel* indexModel = he->indexModel();
  8.     QHelpIndexWidget* indexWidget = he->indexWidget();
  9.  
  10.     QSplitter* splitter = new QSplitter();
  11.     splitter->addWidget(contentWidget);
  12.     splitter->addWidget(indexWidget);
  13.  
  14.     contentWidget->setModel(contentModel);
  15.     indexWidget->setModel(indexModel);
  16.  
  17.     splitter->show();

I took care to call program in the same help.qhc directory.

February 24, 2011

Volker Volker
Ant Farmer
5428 posts

Try it with an absolute path.

For runtime you can use something like this:

  1. QString helpPath = QApplication::applicationDirPath() + "/help_files/help.qhc";

Be aware, that this does not work on the Mac due to the applications bundles used there.

February 24, 2011

willypuzzle willypuzzle
Lab Rat
44 posts

I followed your suggest and this is the new code:

  1.     QFileInfo fileInfo("help.qhc");
  2.     if (fileInfo.exists())   {
  3.  
  4.         QHelpEngine* he = new QHelpEngine(fileInfo.absoluteFilePath());
  5.         he->setupData();
  6.         qDebug() << fileInfo.absoluteFilePath();
  7.         qDebug() << he->error();
  8.  
  9.         QHelpContentModel *contentModel = he->contentModel();
  10.         QHelpContentWidget *contentWidget = he->contentWidget();
  11.         QHelpIndexModel* indexModel = he->indexModel();
  12.         QHelpIndexWidget* indexWidget = he->indexWidget();
  13.  
  14.         QSplitter* splitter = new QSplitter();
  15.         splitter->addWidget(contentWidget);
  16.         splitter->addWidget(indexWidget);
  17.  
  18.         contentWidget->setModel(contentModel);
  19.         indexWidget->setModel(indexModel);
  20.  
  21.         splitter->show();
  22.     }else{
  23.         qDebug() << "File doesn't exist";
  24.     }

It outputs the correct absolute file name(see line 6) and there is no error.
But it doesn’t work….

February 24, 2011

Volker Volker
Ant Farmer
5428 posts

Do you have help.qch in that directory too? It’s needed!

Page  
1

  ‹‹ where are the static libraries for windows distribution?      capture mouse cruising events (buttons not pressed) ››

You must log in to post a reply. Not a member yet? Register here!