Solved Call a class from a different source file
-
void classone::classtwo(void) in the abc.cpp file
in def.cpp file, I want to connect the myaction with the classtwo.
connect(myaction,SIGNAL(triggered())...
What exactly I have to write?
thanks in advance.
-
-
In def.cpp file there is one line:
#include "abc.h"
and the classtwo is a public slot.
If I write:
connect(myaction,SIGNAL(triggered()),this,SLOT(classtwo(void)));
It says:
Object::connect: No such slot ...::classtwo(void) in ..def.cpp
I want it to search not in def.cpp but in abc.cpp
This is what I am asking. What I have to change.
-
what type is
myaction
and what type is*this
? -
QAction* myaction
But I think I have to find a way to call a function in another source file. Something I have to put instead of this.
For example
connect(myaction,SIGNAL(triggered()),void classone::classtwo(void),SLOT(classtwo(void)));
it does not work.
-
you need a pointer to an instance of
classone
. can you post the full content of abc.h, def.cpp and wherever you are calling connect from? -
It is difficult to post all the code. But can you tell me more details about a pointer to an instance of classone? I think I have to do something like this.
-
-
Thanks. This is what I am talking about. In abc.h:
public slots:
void classtwo(void)
How can I call this public slot, not from abc.cpp, but from another .cpp file, for example from def.cpp?
-
To connect, you need two live objects.
So you need to create one. (at least )
somewhere in def.cppOtherClass * oc= new OtherClass(this);
then
connect(this (the def class), (def)signal, oc , theslot (in OtherClass ) )and check you have
Q_OBJECT
in the OtherClass -
Thank you mrjj. This was exactly what I did want.