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:
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
}
}
class worker : public QObject{
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();
}
class mainClass : public QMainWindow, Ui::MainWindow
{
Q_OBJECT
public:
mainClass() : QMainWindow()
{
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
}
}
To copy to clipboard, switch view to plain text mode
This compiles ok with the Q_OBJECT declarations, but I never see pbScanUpdate() running. What could I be missing?
Thanks in advance,
Mr_Cloud
Bookmarks