PDA

View Full Version : I can not do a signal working



franco.amato
4th February 2011, 00:36
Hi I have a clas ( inherited from QObject ) containing a signal.
When I try compile ( with visual studio 2008 ) I get the following error from the compiler:

IrisKernel::sig_userRecognized': invalid call of member function non-static ( translated from Italian ).

This is the class declaration:



class IrisKernel : public QObject
{
Q_OBJECT

public:
IrisKernel(QObject *parent = 0);
virtual ~IrisKernel();

static const QByteArray findMatchingPerson( KSBitVector&, double *mindist );
static void onStoreIrisCodes(IplImage** imageList, QString& dni, bool storeImages);

signals:
void sig_userRecognized(QByteArray&);

protected:
private:
int m_templateSize;
bool m_validated;
};I don't get such error with other classes and the pro file is well edited.
Which can be the error?
Regards

SixDegrees
4th February 2011, 00:42
The error is in your implementation, not your declaration. And the error message you posted tells you exactly what the problem is. Please review basic C++ rules on static members.

ChrisW67
4th February 2011, 00:43
Re-run qmake and then rebuild. Does the error persist?

Edit: SixDegrees is on the money. I misread this as the usual "file has not been moc-ed" problem.

Zlatomir
4th February 2011, 00:44
Is the error code C2352? Then how do you call (emit) the signal?
Like this emit IrisKernel::sig_userRecognized(...);?
Then lose the IrisKernel:: and call emit sig_userRecognized(...);

franco.amato
4th February 2011, 00:51
Re-run qmake and then rebuild. Does the error persist?

Edit: SixDegrees is on the money. I misread this as the usual "file has not been moc-ed" problem.


Re-run qmake and then rebuild. Does the error persist?

Hi yes.
I deleted all visual-studio related files, then I re-run qmake so:

qmake -tp vc myfile.pro

They I built the created solution and the error persist.
Maybe I can not mix static functions and signals into the same class?
Regards


Is the error code C2352? Then how do you call (emit) the signal?
Like this emit IrisKernel::sig_userRecognized(...);?
Then lose the IrisKernel:: and call emit sig_userRecognized(...);

The error is this:

error C2352: 'IrisKernel::sig_userRecognized': chiamata non valida di funzione membro non statica

English translation: call not valid to a non-static function

Zlatomir
4th February 2011, 00:53
I assumed you have an object, don't just try to emit the signal from a static method or try to create a "static" signal.

franco.amato
4th February 2011, 01:07
I assumed you have an object, don't just try to emit the signal from a static method or try to create a "static" signal.

Yes I emit the signal inside a static member. Is this a problem?

Added after 11 minutes:

I changed the method calling the signal from static to non-static and now I don't get the error.
I didn't know that.
I also tried to declare a static signal so:
signals:
static void sameName(SameParams);

but seems the compiler doesn't like it.
I got this new error:

error C2671: 'IrisKernel::sig_userRecognized': le funzioni membro statiche non hanno puntatori 'this'

english translation: static members doesn't have 'this' pointers

I think the only way is to call the non-static signal from a non-static method.

Regards

Zlatomir
4th February 2011, 01:09
Well...
Qt's meta-object system provides the signals and slots mechanism for inter-object communication, run-time type information, and the dynamic property system...
From here (http://doc.qt.nokia.com/latest/metaobjects.html#meta-object-system)
How to communicate between objects if you don't have an object?
And run-time doesn't "interact" well with static (is like you want a static virtual function)

So you will need to redesign your class, and create objects if you want to use signals and slots, else figure out how you can directly call functions.

But anyway why those functions are static?

franco.amato
4th February 2011, 01:13
How to communicate between objects if you don't have an object?
And run-time doesn't "interact" well with static (is like you want a static virtual function)

So you will need to redesign your class, and create objects if you want to use signals and slots, else figure out how you can directly call functions.

But anyway why those functions are static?

Hi thank you very much ( I should improve my c++ knowledge )
I declared them static because I don't really need an object to call such methods.
The methods only work on the params I pass and the class doesn't have any role in the classes diagram.

Zlatomir
4th February 2011, 01:17
You definitely need an object if you want signals and slots.

kornicameister
4th February 2011, 10:26
I don't know if I got Your problem correctly. Sorry, if I did not :)
But I also have some static methods from which I need to emit the signals
my methods need to be static, because I hold pointers to them inside the array
I emit the signal from within the static method using the static selfPointer
like this

emit staticSelfPtr->mySignal()

I do not know how correct this "workaround" is, but is working and I simply need to emit the signal from method which has to be static