QHelpEngine how-to
-
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. -
Yes it works to me too. But why it doesn't work with this code?
@
QHelpEngine* he = new QHelpEngine(":help/help.qhc");QHelpContentModel contentModel = he->contentModel();
QHelpContentWidget contentWidget = he->contentWidget();
QHelpIndexModel indexModel = he->indexModel();
QHelpIndexWidget indexWidget = he->indexWidget();QSplitter* splitter = new QSplitter();
splitter->addWidget(contentWidget);
splitter->addWidget(indexWidget);contentWidget->setModel(contentModel);
indexWidget->setModel(indexModel);splitter->show();
@
Maybe I got wrong in something... -
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() ":http://doc.qt.nokia.com/latest/qhelpenginecore.html#error 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:
@
QHelpEngine* he = new QHelpEngine("./help.qhc");
he->setupData();
qDebug() << he->error();QHelpContentModel *contentModel = he->contentModel(); QHelpContentWidget *contentWidget = he->contentWidget(); QHelpIndexModel* indexModel = he->indexModel(); QHelpIndexWidget* indexWidget = he->indexWidget(); QSplitter* splitter = new QSplitter(); 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:
@
QFileInfo fileInfo("help.qhc");
if (fileInfo.exists()) {QHelpEngine* he = new QHelpEngine(fileInfo.absoluteFilePath()); he->setupData(); qDebug() << fileInfo.absoluteFilePath(); qDebug() << he->error(); QHelpContentModel *contentModel = he->contentModel(); QHelpContentWidget *contentWidget = he->contentWidget(); QHelpIndexModel* indexModel = he->indexModel(); QHelpIndexWidget* indexWidget = he->indexWidget(); QSplitter* splitter = new QSplitter(); 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.... -
Yes, I checked it with
@
qDebug() << fileInfo.absoluteFilePath();
@
that returns the correct absolute file name of the file. -
Ahem sorry, I just tried to put that file in the same directory and it seems to work even though it has strange behavior. I have to study the situation...
However thanks :) -
Sorry to bring up an old thread but I have just spent an embarrassing number of hours on this issue myself. My problem and solution were exactly the same as willypuzzle's, namely that both the .qhc and .qch files must be present.
Looking at those files now, even with my tiny test help pages it's apparent from the file sizes that the .qch contains the actual content, but this is easily overlooked for new users dealing with the plethora of similar file extensions for the first time. Even when the .qch is missing the .qhc is found and loads successfully, and setupData() is successful too, which unfortunately draws attention away from the missing file being the source of the problem.
I think it would be good if it was made clearer in the documentation that both these files are necessary. Specifically, new users will likely arrive at this page as a first reference:
http://qt-project.org/doc/qt-4.8/qthelp-framework.html
From this I got the impression that the compressed help was merely a intermediate step, and the collection was the sole final outcome of the process. -
[SOLVED]
I don't know it is appropriate to ask the question here (if not please say so i'll start a new topic)
I have the problem with an error, it happens when calling the setCollectionFile() funtion of QHelpEngine.
@void HelperWindow::initialize()
{
HelperWindow::setWindowFlags(Qt::WindowStaysOnTopHint);m_helpEngine->setCollectionFile(QApplication::applicationDirPath() + "doc/athleticsmanager.qhc"); m_helpEngine->setupData();
}@
When i look deeper into the code behind this function i get this:
@if (fileName == collectionFile())
return;@It's in the collectionFile() function, that only does
@return d->collectionHandler->collectionFile();@, where i get "Segmentation Fault"
I dont really know what to do now, is there someone who can help me with this problem?
-
I encounter quietly the same problem:
- I am able to load my "doc.qhc" using the Qt Assistant and the content widget contains my documentation sections
- my "doc.qhc" and "doc.qch" are located in the same directory
- when building my help widget (see code below), no error is encountered
- my content widget is empty (the content model has 0 rows)
@
QFileInfo info("doc.qhc");
if (info.exists() == false)
{
qDebug << "Help file does not exist";
}
m_engine = new QHelpEngine(info.absoluteFilePath());
if (m_engine->setupData() == false)
{
qDebug << "Help engine setup failed";
}
QGridLayout* layout = new QGridLayout;
QSplitter* helpPanel = new QSplitter(Qt::Horizontal);
helpPanel->insertWidget(0, m_engine->contentWidget());
m_webView = new QWebView;
helpPanel->insertWidget(1, m_webView);
layout->addWidget(helpPanel, 0, 0);
setLayout(layout);
connect(m_engine->contentWidget(), SIGNAL(linkActivated(QUrl)), SLOT(SetHelpSource(QUrl)));
qDebug() << m_engine->contentModel()->rowCount());
@
I had a look on the Qt Assistant source code and it seems to do the same thing to load a collection file...or I missed something.
Any suggestion?
Thanks in advance for your help