Results 1 to 4 of 4

Thread: Connecting custom class actions

  1. #1
    Join Date
    May 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Connecting custom class actions

    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

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connecting custom class actions

    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.

  3. #3
    Join Date
    May 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connecting custom class actions

    I did try adding Q_OBJECT in the custom class but i get errors.

    undefined reference to `vtable for class_X'

  4. #4
    Join Date
    Oct 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connecting custom class actions

    Sounds like the class is not accessible, if its in another file you did add that file to your project, right?

Similar Threads

  1. Connecting signal to custom slot?
    By dbrmik in forum Qt Tools
    Replies: 2
    Last Post: 30th April 2009, 09:28
  2. custom class for tslib
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 28th April 2009, 13:15
  3. Replies: 4
    Last Post: 16th November 2008, 13:53
  4. How to store custom class in QHash?
    By Misenko in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 08:57
  5. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 22:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.