Use the show QtAssistant
QtAssistant the display is the most common I think.
First, QtAssistant we'll see.
QtAssistant earlier, for the view class (QAssistantClient) were.
This is, prima facie, it seems to work now, so is not recommended here, do not use.
This is recommended QtProcess describes how to start with easily.
This sample is composed of the following file.
- sample.cpp
- Main program.
Skip MainWindow is a detailed description of the screen.
- 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.
Qt use the Help file,
use the HELP QtAssistant created in
a file doc.qch, collection_doc.qhc used.
[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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
| #include "mainwindow.h"
#define HELP_FILE "collection_doc.qhc"
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_help_act = pfileMenu->addAction("H&elp" );
m_help_act->setShortcut(QKeySequence(QKeySequence::HelpContents));
m_help_act->setStatusTip(tr("Show help"));
m_help_change_act = pfileMenu->addAction("Change Page Help" );
m_help_change_act->setStatusTip(tr("Change Page Help"));
m_help_change_act->setEnabled(false);
m_exit_act = pfileMenu->addAction(tr("E&xit" ));
m_exit_act->setShortcut(tr("Ctrl+Q"));
m_exit_act->setStatusTip(tr("Exit the application"));
// create help process.
m_process_help = new QProcess(this);
m_help_exec=false;
// action connect.
connect(m_help_act, SIGNAL(triggered()),
this, SLOT(OnHelp()));
connect(m_help_change_act, SIGNAL(triggered()),
this, SLOT(OnHelpChange()));
connect(m_exit_act, SIGNAL(triggered()),
qApp, SLOT(closeAllWindows()));
connect(m_process_help,SIGNAL(started()),
this,SLOT(OnStartedHelp()));
connect(m_process_help,SIGNAL(finished(int , QProcess::ExitStatus )),
this,SLOT(OnEndHelp(int , QProcess::ExitStatus )));
setWindowTitle(tr("SampleWindow"));
resize(400, 300);
}
void MainWindow::OnHelp()
{
QStringList args;
args << QLatin1String("-collectionFile")
<< ( qApp->applicationDirPath() + "/" + HELP_FILE )
<< QLatin1String("-enableRemoteControl");
m_process_help->start(QLatin1String("assistant"), args);
}
void MainWindow::OnHelpChange()
{
QByteArray ba;
ba.append("setSource qthelp://Sample_Help/doc/doc2.html");
ba.append('\0');
m_process_help->write(ba);
}
void MainWindow::OnStartedHelp()
{
m_help_exec=true;
statusBar()->showMessage(tr("Started HELP(Assistant)."));
m_help_act->setEnabled(!m_help_exec);
m_help_change_act->setEnabled(m_help_exec);
}
void MainWindow::OnEndHelp(int , QProcess::ExitStatus )
{
m_help_exec=false;
statusBar()->showMessage(tr("Closed HELP(Assistant)."));
m_help_act->setEnabled(!m_help_exec);
m_help_change_act->setEnabled(m_help_exec);
}
|
Make a simple explanation.
Lines 9-12, the menu, I have created a status bar.
Lines 15-25 are where the action is created.
- m_help_act: QtAssistant action to start.
- m_help_change_act: QtAssistant action switch pages.
- m_exit_act: The action to terminate the application.
Line 27-28, QtAssistant you start QProcess I have created.
Line 50-57, QProcess using QtAssistant We are starting up.
For more about the command parameters,
http://doc.trolltech.com/4.5/assistant-details.html please see the.
Line 58-64, QProcess I'm using a switch QtAssistant page.
For more about the command parameters,
http://doc.trolltech.com/4.5/assistant-custom-help-viewer.html please see the.
After the first 65 rows, QtAssistant Once the process is to enable the switching action.
Once you have QtAssistant process and disable the switching action.
It's easy.
QProcess to pass parameters to the startup, QString (List) at (QtAssictant specified as startup parameters),
but after starting, switch to the communication process, send with QByteArray (QtAssictant command parameters specified).
The screen displays the following to compile and run it.
This is just a simple menu screen.
So, File menu, Help'll click.
QtAssistant will be shown like a following image.
Continues, File menu, Change Page Help Click Let.
QtAssistant will be changed page like a following image.
Qt help files (qch files, qhc file) is unique in Qt applications, it can be shown.
In his own Qt I'd like to see a brief description of the application.
Show original application
The following QtAssistant try to create a screen.
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.
Line 20-21, QHelpEngine I have created.
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.
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.
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.
Leave a Reply