Results 1 to 5 of 5

Thread: Signal/Slot problem by subclassing from QTreeWidgetItem

  1. #1

    Default Signal/Slot problem by subclassing from QTreeWidgetItem

    Hi there,

    I've got a Problem. Sorry for my bad english, that the reason why I want to show you my code. This tells more than my 1000 words...
    1st my Class,
    Qt Code:
    1. using namespace MyNamespace;
    2. class MyTreeWidgetItem : public QTreeWidgetItem
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. SingleScanTreeWidgetItem(QTreeWidget *parent);
    8. ~SingleScanTreeWidgetItem();
    9.  
    10. void makeActions(QMenu* menu);
    11.  
    12. public slots:
    13. void onAction();
    14. };
    To copy to clipboard, switch view to plain text mode 

    Okay, and here is my implementation:
    Qt Code:
    1. MyTreeWidgetItem::MyTreeWidgetItem(QTreeWidget *parent)
    2. : QTreeWidgetItem(parent)
    3. {
    4. setText(0,"The Text");
    5. }
    6.  
    7. MyTreeWidgetItem::~MyTreeWidgetItem()
    8. {
    9. }
    10.  
    11. void MyTreeWidgetItem::makeActions(QMenu* menu)
    12. {
    13. QAction* action = new QAction(QString("Test"),menu);
    14. menu->addAction(action);
    15.  
    16. QObject::connect(action,SIGNAL(triggered()),this,SLOT(onAction()));
    17. }
    18.  
    19. void MyTreeWidgetItem::onAction()
    20. {
    21. int test(0);
    22. }
    To copy to clipboard, switch view to plain text mode 

    So, thats all. But my compiler gives my an error:
    CompileError C2665:
    'function' : none of the number1 overloads can convert parameter number2 from type 'type'
    So whats my mistake? How can I solve this problem?
    Did anybody knows that?

    Ciao + Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal/Slot problem by subclassing from QTreeWidgetItem

    QTreeWidgetItem does not inherit QObject.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Signal/Slot problem by subclassing from QTreeWidgetItem

    How can I solve this problem?
    I want to have a context menu on my TreeWidgetItems.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal/Slot problem by subclassing from QTreeWidgetItem

    You want to have context menu on your table widget, not its items. So implement it there using the regular means available for widgets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Signal/Slot problem by subclassing from QTreeWidgetItem

    first of all your constructor name does not match class name :]
    second of all add you context menu to your QTreeWidget not to your items. Then check which item was clicked
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 2
    Last Post: 20th September 2007, 12:27
  2. problem with signal/slot
    By ihoss in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 22:59
  3. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 18:34
  4. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  5. Problem in SubClassing QTableItem.
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2006, 10:21

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.