hello guys
i want to call a function in one cpp file from another cpp file.
and i have written this function to slot
Can anyone please help me in this
P.S. i have added header file of second file(where the function is) also in the first file.
hello guys
i want to call a function in one cpp file from another cpp file.
and i have written this function to slot
Can anyone please help me in this
P.S. i have added header file of second file(where the function is) also in the first file.
C++ doesn't make any distinction on where a function is defined.
If it is declared, as it should be for you since you included the header that declares it, just call it.
Cheers,
_
i am calling it in slot but its not working.
means this function is attached to pushbutton, when i click pushbutton its not calling the function.
can you help in this.
Thanks
Can you show some code. Hard to know where you are going wrong
i cant show the code but abstact is as follows
Header.h
{
class ap
void open();
}
call.cpp
include header.h
{
class ap:: open()
{
}
}
on.cpp
include header.h
{
connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
}
I think i am not sure
problem is i am using 'this' in connect command that why its not working what shuld i write instead of that
1. Inherit QObject.
2. Use Q_OBJECT macro.
3. Declare this function as a slot.
I have written Q_OBJECT in Header.h
and sorry i didnt get what you have written plz can u explain in detail
i added header file in the program but then also its not working i have to create instance, with this it will work i guess i did that also means i created one object of the class where the function is and put that object in connect commad but its not working please help
can a one give me an exmaple or a link for callin a function from other cpp file so that i will get an idea how to do that.
There is an example in the link I've posted.
Additionally most examples that come with Qt are doing that.
Cheers,
_
Here is an example of calling "funToCall()" defined in file1.cpp from within file2.cpp:
file1.cpp:
Qt Code:
#include <cstdio> void funToCall() { printf("Someone called?\n"); }To copy to clipboard, switch view to plain text mode
file1.h:
file2.cpp:
Qt Code:
#include "file1.h" void main() { funToCall(); }To copy to clipboard, switch view to plain text mode
However I'm sure the question you asked was not really the one you needed to have an answer to.
actually the problem is when i define the class contructor it has arguments in it thats why i am not able to create object.Do you know any solution regrading this how can i create object of a class whose constructor has arguments like bool*a,QWidget *parent = 0
means
ap(bool*a ,QWidget *parent = 0,QObject *parent)
Why would that be a problem?
Just pass the required values, like for any other function.
Cheers,
_
Bookmarks