PDA

View Full Version : Opening a Dialog from a MainWindow FileMenu



nbkhwjm
17th April 2007, 00:31
All I have created a MainWindow Application Called "porcupine" This has a File menu where you *should* be able to open a QDialog (preferences.ui) file to set the application preferences.

I set the Signals and Slots to point to a Function:


void Porcupine::showPrefs()
{

qDebug("Open Prefs Window");

Preferences *prefs = new Preferences(this);
prefs.exec();

}


I get the following errors...


porcupine.cpp: In member function `void Porcupine::showPrefs()':
porcupine.cpp:257: error: no matching function for call to `Preferences::Preferences(Porcupine* const)'
preferences.h:18: note: candidates are: Preferences::Preferences(const Preferences&)
preferences.h:22: note: Preferences::Preferences()
porcupine.cpp:258: error: request for member `exec' in `prefs', which is of non-class type `Preferences*'

I know this is a classing problem, but i keep getting all messed up dealing with the autocreated H files from designer...

Thanks...

jacek
17th April 2007, 00:39
Preferences *prefs = new Preferences(this);
There is no such constructor declared in preferences.h --- there's only Preferences::Preferences().


prefs.exec();
prefs is a pointer, so it should be "prefs->exec();".

nbkhwjm
17th April 2007, 00:43
how should I declare this? and additional class?

marcel
17th April 2007, 05:15
1. You should use an additional class for your dialog, not the main window class.
2. The ui_porcupine.h file is automatically generated by the uic ( UI compiler ). All you have to do is include it in your dialog header. You must not modify/or care about this file, because it will be overwritten each time you modify something in the ui.

To show it using a menu, I think you first should read the Menus example in the Main Windows section from the examples and demos. This should help you a bit.

Also, have a look at the Qt Designer manual ( int the Assistant ).

BTW: what is a porcupine?
Edit - nevermind :). I know now, but it sounds so funny...


Regards

jacek
17th April 2007, 12:24
how should I declare this?
It should be: "Porcupine::Porcupine( QWidget *parent = 0 )".