Results 1 to 5 of 5

Thread: QStyledItemDelegate Weird Error

  1. #1
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Unhappy QStyledItemDelegate Weird Error

    Hi.

    I'm subclassing a QStyledItemDelegate in order to attach it to a QTableWidget.
    It is working fine but I want to emit a signal from the delegate when I do some stuff inside the call of reimplemented QStyledItemDelegate::setEditorData, for instance:

    Qt Code:
    1. class MyDelegate : public QStyledItemDelegate
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyDelegate(QObject* parent);
    7. QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    8. virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
    9. virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    10. virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    11.  
    12. signals:
    13. void mySignal(int value);
    14.  
    15. };
    16.  
    17. void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
    18. {
    19. int i = 1;
    20. ...do some stuff...
    21.  
    22. emit mySignal(i);
    23. }
    To copy to clipboard, switch view to plain text mode 

    However I have a problem that I can't understand... The compiler is telling me:
    "error: passing 'const MyDelegate' as 'this' argument of 'void MyDelegate::mySignal(int)' discards qualifiers"

    I can't understand this error if I'm passing an int as an argument, not a "MyDelegate"...
    If someone can explain or knows something about this or maybe, if anyone thinks that this is a bug...
    Well, any help is appreciated...

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QStyledItemDelegate Weird Error

    Define the signal this way,
    Qt Code:
    1. ...
    2. signals:
    3. void mySignal(int value) const;
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by Santosh Reddy; 19th July 2011 at 18:31. Reason: spelling corrections

  3. The following user says thank you to Santosh Reddy for this useful post:

    daleotar (19th July 2011)

  4. #3
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyledItemDelegate Weird Error

    Thanks Santosh for your very opportune reply like always...

    Well, Now it works, thanks a lot... However now my question is why do we have to define the signal as a const?

    Again...Thanks a lot, XD
    Last edited by daleotar; 19th July 2011 at 18:50.

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QStyledItemDelegate Weird Error

    a const function can call only another const function(s), signal is also a function, but you don't need to implement it, Qt (moc) will implement it for you.

  6. #5
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyledItemDelegate Weird Error

    thanks for the clarification, I'm feeling like an idiot because the solution is kinda obvious, XD

Similar Threads

  1. QtCreator weird error while trying to use libnotify libs
    By hakermania in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2011, 11:42
  2. QSqlQuery.exec() weird error
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2010, 13:02
  3. Weird QTextEdit error
    By MarkoSan in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2008, 10:05
  4. Weird compile error
    By MarkoSan in forum Qt Programming
    Replies: 6
    Last Post: 3rd December 2007, 18:50
  5. weird error
    By mickey in forum General Programming
    Replies: 6
    Last Post: 18th November 2006, 04:22

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
  •  
Qt is a trademark of The Qt Company.