Signal and slot problem
-
@mrjj Sir, ISR() is a static function. So to access other functions of the class i need to create an object :) thats why i have defined two other function emit_RisingEdge() and emit_FallingEdge() so i can emit my signals independent of any object.
-
Hi,
Just one thing, you have now a memory leak.
But in any case, I must say I don't see any reason for making all these methods static.
-
-
@azravian In this case you could add a public static method to get the pointer to the gpio instance (basically you create a singleton):
class gpio : public QObject { Q_OBJECT public: gpio(): instancePtr(nullptr) {} static gpio* instance() { if (!instancePtr) instancePtr = new gpio(); return instancePtr; } private: gpio* instancePtr;
You can use this method in main to setup the connection and in static methods in gpio to get the pointer to the instance. Don't forget to delete the instance later.
-
-
Silly question but are you user the label is visible ? Do you have something on it before you call inserted ?
-
Then do you have something else that modifies that label ?
Things would be a bit easier if there was a possibility to see your code.
-
@SGaist
Sure Sir, it's the same code except i added just one line#include "mainwindow.h" #include "ui_mainwindow.h" #include "gpio.h" #include <QDebug> bool firstTime=true; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { if(firstTime) { gpio::Initialize(); firstTime=false; } gpio* GPIO=new gpio; connect(GPIO,SIGNAL(RisingEdge()),this,SLOT(inserted())); connect(GPIO,SIGNAL(FallingEdge()),this,SLOT(Removed())); delete GPIO; ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::inserted() { qDebug()<<"Inserted..."; ui->label->setText("Inserted"); } void MainWindow::Removed() { ui->label->setText("Inserted"); qDebug()<<"Removed..."; }
-
If I may, you really should first cleanup your gpio class. It looks wrongly implemented and is wrongly used.
Make it a normal object i.e. don't use any static in it and don't make it a singleton. Once you have that sorted, it will be easier to integrate it in your GUI.