PDA

View Full Version : Making some simple help for my application



Godlike
21st April 2006, 07:41
How can i make some little help when i click on a help button.
Something like this here:

http://img81.imageshack.us/my.php?image=untitled3sj.jpg

Is there some example how i can make this window here ?

Thx.

wysota
21st April 2006, 10:45
Either use "What's this" capabilities or look at the simple help browser video (http://www.trolltech.com/video/index.html).

Godlike
21st April 2006, 13:36
Ok used the video, all fine. But i cant get that include right: ui_browser.h

When i compile it doesnt find it. It must be in the directory where i compile probably, so where can i get that file ?

wysota
21st April 2006, 14:21
It should get created by uic from your ui file. Make sure the ui file you created in Designer is mentioned in the FORMS section of the project file.

Godlike
21st April 2006, 14:36
I made that form in the QT designer 4.0 and then when i was done i saved it as form.ui and that is all i have in my directory. So where should i check that what you said ?

wysota
21st April 2006, 15:24
The .pro file should contain an entry in its FORMS section about that designer made file. If it doesn't have it, you should add FORMS+=filename.ui and rerun qmake.

Godlike
21st April 2006, 15:51
It contains it.

FORMS += form.ui

it was there from beggining.

ahhh its ui_form.h not same as by the example because i changed name :)
Stupid me :o

Stil cant integrate it to my application :(

I have it like this:

main.cpp



int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ImageViewer imageViewer;
imageViewer.show();
return app.exec();
}


imageviewer.h



class QMainWindow;


imageviewer.cpp



ImageViewer::ImageViewer()
{
QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);
ui.textBrowser->setSource(QString("/home/godlike/RA/test/index.html"));
}

void ImageViewer::createActions()
{
helpAct = new QAction(tr("&Help"), this);
helpAct->setShortcut(tr("Ctrl+H"));
connect(helpAct, SIGNAL(triggered()), this, SLOT(help()));
}

void ImageViewer::help()
{
statusBar()->showMessage(tr("Help"));
form->show();
}


I only pasted relevant code for this problem. I will paste the error i get from compile:

imageviewer.cpp:26: error: ‘MainWindow’ is not a member of ‘Ui’
imageviewer.cpp:26: error: expected `;' before ‘ui’
imageviewer.cpp:27: error: ‘ui’ was not declared in this scope

Something with that Ui but i dont know what i did wrong with it.
Thx for help so far, help abit more and i will learn something new again :D

jacek
21st April 2006, 17:03
Ui::MainWindow ui;
This should be a member variable of the ImageViewer class.

Make sure that you have #include "ui_something.h" and that your form is named MainWindow (check objectName property in the Designer).

Godlike
21st April 2006, 17:10
Yep moved to .h file and corrected the name. Compiles great now. But if i click my button help, signal connects to function help(), its posted one post above, i get segmentation fault and my app crashes :eek:

Anything i made wrong, again ? :crying:

Though it had to do something that i used QMainWindow so i made it as QWidget, still same problem, but if i move my form->show(); out of help() to the top where i do ui.setup ... it goes fine, but it starts when program starts, i want it to show when i click on help, so how can this be done correctly ?

Argh, got it. Why would i make that widget before calling help() thats stupid :p

I just made it when i called help(), works fine. Sorry for asking too soon.

Thanks for all the help. Great forum!

jacek
21st April 2006, 18:43
ImageViewer::ImageViewer()
{
QMainWindow *form = new QMainWindow;
...
}
You have two form variables --- one is a member variable in of the ImageViewer and another one is a local variable that you use in the constructor. There should be only one.

BTW. It would be better if you create a separate class for that help browser.