[Signals & Slots] Custom class' signal not detected
Hello All,
I've looked into how to write a class with QObject's inheritance so I can use signals as I need feedback from said class. The trouble is, I'm not sure if I defined the signal correctly, as it differs from the Signals & Slots example.
My code is as follows:
Code:
Q_OBJECT
public:
worker();
void execute (bool isExecuting){
if (isExecuting==true){
//do stuff
emit scanUpdate(); //differs from the example's ValueChanged(int newValue)
}
else return;
}
signals:
void scanUpdate();
}
{
Q_OBJECT
public:
{
setupUi(this);
lib=new worker;
connect(lib,SIGNAL(scanUpdate()),this,SLOT(pbScanUpdate()));
while(1){ lib->execute(true); }
}
worker *lib;
public slots:
void pbScanUpdate(){
//do stuff which can only occur after lib->execute has been called
}
}
This compiles ok with the Q_OBJECT declarations, but I never see pbScanUpdate() running. What could I be missing?
Thanks in advance,
Mr_Cloud
Re: [Signals & Slots] Custom class' signal not detected
You are missing "slot:" keyword before "void pbScanUpdate()" declaration/definition
Re: [Signals & Slots] Custom class' signal not detected
You are also ignoring the warning messages in your program output that will be telling you that there is no slot named pbScanUpdate().
Re: [Signals & Slots] Custom class' signal not detected
Sorry you're right. I copy-pasta'd wrong, there is actually public slots: declaration before void pbScanUpdate(). Top post edited.
Re: [Signals & Slots] Custom class' signal not detected
Are you sure the "emit"-statement gets called?
Re: [Signals & Slots] Custom class' signal not detected
It will not compile!
You better get the code compiling and then organize the code such that you can at-least insert break-points on individual line. Your code will work perfectly if you fix the "worker" constructor (implementation is missing, how come it will compile), and class terminating ";" (It will for sure not compile).
Also note that you have while(1) loop in ctor, you will never be able to see the window pop up. Breakpoint is the only way you can see it work.