Since you create the dialog with the main window as parent, you could do a cast to get an instance of the window type:
Qt Code:
((MainWindowClass*)parent())->resetKey(K2);To copy to clipboard, switch view to plain text mode
Regards
Since you create the dialog with the main window as parent, you could do a cast to get an instance of the window type:
Qt Code:
((MainWindowClass*)parent())->resetKey(K2);To copy to clipboard, switch view to plain text mode
Regards
Backslash (2nd August 2007)
I'm sorry, but I don't quite understand what doing a cast means.
The MainWindow instance is called mainWin (from main.cpp)
Qt Code:
MainWindow mainWin; mainWin.show(); return app.exec();To copy to clipboard, switch view to plain text mode
So do you mean for me to write:
((MainWindow*)parent())->resetKey(K2);
or something else entirely?
Thanks,
Backslash
Yes, the easiest way is to do that.
In on_buttonBox_accepted, replace the last line with:
Qt Code:
((MainWindow*)parent())->resetKey(K2);To copy to clipboard, switch view to plain text mode
Should work.
To find out what a cast is, do a search on google on"c++ inheritance and polymorphism".
Regards
Backslash (2nd August 2007)
Thanks again for the help,
When I use that line "((MainWindow*)parent())->resetKey(K2);" I get this error message from make:
keydialog.cpp: In member function `void KeyDialog:n_buttonBox_accepted()':
keydialog.cpp:117: error: `MainWindow' undeclared (first use this function)
keydialog.cpp:117: error: (Each undeclared identifier is reported only once for
each function it appears in.)
keydialog.cpp:117: error: expected primary-expression before ')' token
keydialog.cpp:117: error: expected `)' before "parent"
mingw32-make[1]: *** [release\keydialog.o] Error 1
Did I misunderstand something?
You have to include MainWindow.h in keydialog.cpp.
A more elegant solution is to create a getter in the keydialog. This will return the key (K2).
So, in the slot on_push_0_clicked, you can do:
RegardsQt Code:
{ Key::Key k = dialog.getKey2(); resetKey(k); }To copy to clipboard, switch view to plain text mode
Backslash (2nd August 2007)
Wow, that is a neat solution. Definitely going to try that one...
Thanks for the patience and the insight,
Backslash
Is this the order in which I should put this?
Qt Code:
void MainWindow::on_push_0_clicked() { KeyDialog dialog(this); dialog.setKey(zero); dialog.exec(); { Key::Key k = dialog.getKey(); resetKey(k); } }To copy to clipboard, switch view to plain text mode
In KeyDialog, My getKey(); looks like this:
Qt Code:
Key getKey() { return K2; }To copy to clipboard, switch view to plain text mode
(K2 is defined at the top of KeyDialog because I use on_buttonBox_accepted to take the current state of the form's widgets and translate those into values to be stored in K2)
All of this seems ok to me but I'm getting a wierd error from make:
release\mainwindow.o(.text+0x8455):mainwindow.cpp: undefined reference to `KeyDi
alog::getKey()'
release\mainwindow.o(.text+0x9915):mainwindow.cpp: undefined reference to `KeyDi
alog::getKey()'
release\mainwindow.o(.text+0xadd5):mainwindow.cpp: undefined reference to `KeyDi
alog::getKey()'
release\mainwindow.o(.text+0xc295):mainwindow.cpp: undefined reference to `KeyDi
alog::getKey()'
release\mainwindow.o(.text+0xd755):mainwindow.cpp: undefined reference to `KeyDi
alog::getKey()'
release\mainwindow.o(.text+0xec15):mainwindow.cpp: more undefined references to
`KeyDialog::getKey()' follow
collect2: ld returned 1 exit status
I have no clue what that's about...
Thanks again,
Backslash
Well, this looks like c++ mistake:
When you implement a function in a class, you have to prepend the name of the class and the resolution operator to it:
Now, K2 has to be a member of the class in order to be visible in any of the class's member functions.Qt Code:
Key::Key KeyDialog::getKey() { return K2; }To copy to clipboard, switch view to plain text mode
Also, the correct thing to do is:
exec(), by default, returns an exit code which shows you whether the user pressed ok or cancel( accepted or rejected).Qt Code:
void MainWindow::on_push_0_clicked() { KeyDialog dialog(this); dialog.setKey(zero); { Key::Key k = dialog.getKey(); resetKey(k); } }To copy to clipboard, switch view to plain text mode
So you need to call exec only once.
The compile errors tell you that you did not declared/defined the getKey function.
To declare a function - means you add it in the class declaration, in the header:
The function definition means the implementation. It appears that you have donh that( incorrectly although ).Qt Code:
class KeyDialog : ... { public: Key::Key getKey(); };To copy to clipboard, switch view to plain text mode
So, fix these errors and try again.
Regards
Backslash (3rd August 2007)
Thanks for all the help. I'm glad there's a newbie section of this forum.
Now I just have to work out some more kinks in my code and implement a few more functions.
Thanks again,
Backslash
Bookmarks