PDA

View Full Version : Connecting custom class actions



Toshikazu
14th October 2009, 23:20
Hey

I have a class X which inherits from QTreeWidget. I have overloaded the contextMenuEvent so I can create a mouse right click menu for the items. I cannot find a clean and easily scalable method of linking all of the menu actions to functions within class X.

Initially I thought I could connect a class X function to a class X action within the class X constructor. It wouldn't compile. I had to do the connection in the MainWindow constructor, connecting the Qaction in class X with a function in MainWindow. The function in MainWindow then had to call a function in Class X. This appears very sloppy and un-scalable. Are there any nicer ways to do this. And is it possible to do connections inside custom classes?

Thank you

squidge
15th October 2009, 00:12
I'm only a noob, but I *think* you can have the connect call in any class which has Q_OBJECT at the top as long as you include the header file which contains your actions (most likely ui_*.h), although I've not tested it yet.

Toshikazu
15th October 2009, 00:34
I did try adding Q_OBJECT in the custom class but i get errors.

undefined reference to `vtable for class_X'

Steven
15th October 2009, 16:31
Sounds like the class is not accessible, if its in another file you did add that file to your project, right?