Results 1 to 3 of 3

Thread: a signal-slot issue

  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default a signal-slot issue

    Hello, friends!
    I want to create a special version of QTableWidget that does special things when it is clicked on some if its cells.
    I will reuse it several times.
    I've created a new class SelVarTable
    Qt Code:
    1. class SelVarTable
    2. {
    3. Q_OBJECT
    4. private:
    5. QTableWidget *myTable;
    6. // some other stuff
    7. public slots:
    8. void cellClicked_(int r, int c);
    9. // some other stuff
    10. };
    To copy to clipboard, switch view to plain text mode 
    and I wrote the following initialization code:
    Qt Code:
    1. SelVarTable::SelVarTable(QWidget *parent)
    2. {
    3. myTable=new QTableWidget(parent);
    4. // some other stuff
    5. QObject::connect(myTable, SIGNAL(cellClicked(int,int)), this, SLOT(cellClicked_(int,int)));
    6. }
    To copy to clipboard, switch view to plain text mode 

    But when I compile I get for the QObject::connect (row 5 of the above code) command the following error
    error: no matching function for call to 'QObject::connect(QTableWidget*&, const char*, SelVarTable* const, const char*)'
    candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
    note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const
    note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const

    I could not understand what is wrong.
    I cannot believe that it is not possible to connect a signal in a QWidget to a slot in a class that has that QWidget as one of its elements.

    I've also tried a totally different way (inheriting SelVarTable from QTableWidget) but had other issues. I first will try to understand why this code does not work.

    Someone can help?

    Thank you.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: a signal-slot issue

    Your problem is the class, it contains Q_OBJECT macro, but it doesn't derive from QObject class or any other class derived from QObject (so your class is not a QObject)
    So derive from QObject if you need signals and slots or QWidget if you need to show and do other specific Widget stuff...
    Qt Code:
    1. class SelVarTable : public QWidget //i just guess you need QWidget since you have GUI stuff in there
    2. {
    3. Q_OBJECT
    4. public: SelVarTable(QWidget* parent//.... don't forget the parent/child
    5. private:
    6. //...
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: a signal-slot issue

    oh, I see.
    Now I understand.
    I'checked and solved my problem.
    Many thanks.

Similar Threads

  1. Signal / Slot issue
    By sicker in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2011, 22:53
  2. QFileDialog Signal / Class Slot issue
    By Wasabi in forum Newbie
    Replies: 5
    Last Post: 8th August 2010, 00:48
  3. qt signal/slot auto-connect issue
    By parnedo in forum Qt Programming
    Replies: 9
    Last Post: 16th July 2009, 13:55
  4. Signal and Slot Issue
    By dlrlsqa1 in forum Newbie
    Replies: 5
    Last Post: 23rd March 2009, 13:44
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 19:52

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.