PDA

View Full Version : Unused parameters in slots



ePharaoh
22nd March 2006, 07:53
I have declared a slot as follows,


class Shell {
Q_OBJECT
public slots:
void treeExpanded (const QModelIndex &index);
}


Now, I don't have a use for the index parameter. Gcc gives a warning in this case, saying index is unused. (I try to keep my code free of warnings :rolleyes: )

Now, if I don't want that warning I can say,


class Shell {
Q_OBJECT
public slots:
void treeExpanded (__attribute__((unused)) const QModelIndex &index);
}


The warning goes off but the moc generated bad code. I get a compile error for the moc_Shell.cpp


moc_Shell.cpp: In member function `virtual int
Shell::qt_metacall(QMetaObject::Call, int, void**)':
moc_Shell.cpp:78: error: parse error before `*' token


Is there any solution to this? Thanks...

zlatko
22nd March 2006, 08:03
Yes ;)


//// *.h
void treeExpanded (const QModelIndex &);

//// *.cpp
void Shell::treeExpanded (const QModelIndex &)
{
}

jpn
22nd March 2006, 08:14
Or Q_UNUSED (http://doc.trolltech.com/qtopia4.1/html/qtglobal.html#Q_UNUSED)

ePharaoh
22nd March 2006, 08:30
Thanks, zlatko; it worked.

I ain't familiar with the quirks of C++.