PDA

View Full Version : a signal-slot issue



ceraolo
28th April 2012, 11:34
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


class SelVarTable
{
Q_OBJECT
private:
QTableWidget *myTable;
// some other stuff
public slots:
void cellClicked_(int r, int c);
// some other stuff
};

and I wrote the following initialization code:


SelVarTable::SelVarTable(QWidget *parent)
{
myTable=new QTableWidget(parent);
// some other stuff
QObject::connect(myTable, SIGNAL(cellClicked(int,int)), this, SLOT(cellClicked_(int,int)));
}


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.

Zlatomir
28th April 2012, 12:12
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...

class SelVarTable : public QWidget //i just guess you need QWidget since you have GUI stuff in there
{
Q_OBJECT
public: SelVarTable(QWidget* parent//.... don't forget the parent/child
private:
//...

ceraolo
28th April 2012, 18:30
oh, I see.
Now I understand.
I'checked and solved my problem.
Many thanks.