Qt (8)-3 How to show QtHelp Files
Published on| June 26th, 2009 | No Comment.
Categories:Qt |

This sample is composed of the following file.
- sample.cpp
- Main program. Skip MainWindow is a detailed description of the screen. - helpbrowser.h
- QTextBrowser is inherited HelpBrowser header screen. Omit a detailed explanation. - helpbrowser.cpp
- HelpBrowser source screen. And a detailed explanation later. - mainwindow.h
- QMainWindow MainWindow is inherited header screen. Omit a detailed explanation. - mainwindow.cpp
- MainWindow is the source of the screen. And a detailed explanation later.
[helpbrowser.cpp]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <QHelpEngine> #include "helpbrowser.h" HelpBrowser::HelpBrowser(QHelpEngine *helpEngine, QWidget *parent) : QTextBrowser(parent), helpEngine(helpEngine) { } QVariant HelpBrowser::loadResource(int type, const QUrl &url) { if (url.scheme() == "qthelp") return QVariant(helpEngine-->fileData(url)); else return QTextBrowser::loadResource(type, url); } |
Make a simple explanation.
loadResource We are simply overloaded. Non QHelpEngine get the constructor does not have any changes.
Over the loadResource in Rhodes, QHelpEngine, url specified in the HTML document looking for and what it returns.
It's easy.
[mainwindow.cpp]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // create menu. QMenu * pfileMenu = menuBar()-->addMenu(tr("&File")); // create status bar. QStatusBar *pstatus= statusBar(); pstatus-->showMessage(tr("Ready")); // create action m_exit_act = pfileMenu-->addAction(tr("E&xit" )); m_exit_act-->setShortcut(tr("Ctrl+Q")); m_exit_act-->setStatusTip(tr("Exit the application")); QSplitter *helpPanel = new QSplitter(Qt::Horizontal,this); // help engine. m_helpEngine=new QHelpEngine(qApp-->applicationDirPath()+"/collection_doc.qhc",this); m_helpEngine-->setupData(); m_phtml=new HelpBrowser (m_helpEngine,this); helpPanel-->insertWidget(0, m_helpEngine-->contentWidget()); helpPanel-->insertWidget(1, m_phtml); setCentralWidget(helpPanel); // action connect. connect(m_exit_act, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); connect(m_helpEngine-->contentWidget(), SIGNAL(linkActivated(const QUrl &)), m_phtml, SLOT(setSource(const QUrl &))); setWindowTitle(tr("SampleWindow")); resize(400, 300); } |
Make a simple explanation.
Lines 7-10, the menu, I have created a status bar.
Lines 12-15 are where the action is created.
- m_exit_act: The action to terminate the application.
collection_doc.qhc arguments are passed to the full path information.
Line 22 is the address I have created HelpBrowser.
QHelpEngine is passed as an argument.
Line 32-34, QHelpEngine When you click the link in the information content of the screen, where the setSource HelpBrowser to start and connect.
You can create a simple, non.
Screen appears where you run and compile it.
When compiled, the command parameters as follows: the capture or QTHELP,. Pro needs to be appended to.
> qmake "CONFIG+=HELP"
However, the Qt help files can be read here, will require some modifications.
QtAssistant it does not load, HELP Project collection file(.qhcp) the assistant to erase all the tags, Qt must help rebuild the file.
QtAssistant it does not load, HELP Project collection file(.qhcp) the assistant to erase all the tags, Qt must help rebuild the file.
It would be easy to except a little surprised.
Here, it was not introduced, yet, QtHelp classes are related.
For example, QHelpSearchEngine, can be searched.
More usefull, QtAssistant can embed it in your application's features.
Here, it was not introduced, yet, QtHelp classes are related.
For example, QHelpSearchEngine, can be searched.
More usefull, QtAssistant can embed it in your application's features.
Pages: 1 2
You might also like:
Trackback URL
After Admin approves this comment, it will be shown.
Comments
Leave a Reply
