Calling a class function from an class array of non class functions.
-
My issue occurs when I am trying to call a member function in a non-member function that is used in a member array of functions in a state event table. I have included a lot of information below, but in essence if the array calls a nop() function or a p_wait function that only calls other non member functions , Every thing works. But if The array calls lrun() non-member function the program crashes with a segment error.
Does anyone have any ideas??
Thanksstateevent.h
extern unsigned int nop(struct linestatus *); extern unsigned int lrun(struct linestatus *); extern unsigned int p_wait(struct linestatus *); extern unsigned int sp_scrap(struct linestatus *); class StateEvent : public QDialog { Q_OBJECT public: explicit StateEvent( QWidget *parent = nullptr); ~StateEvent(); Ui::StateEvent *seui; event_handler StateEventTable[MEVENT][MSTATE] = { /*ev 0*/ {waite, lrun, nop, cont, }, /*ev 1*/ {nop, nop, nop, p_wait}, /*ev 2*/ {nop, nop, nop, nop, }, /*ev 3*/ {nop, sp_scrap, nop, nop} }; private: StateEvent sefunc(); };
stateevent.cpp
unsigned int p_wait(struct linestatus *curlsptr) { return(sechk(curlsptr)); } **unsigned int lrun(struct linestatus *curlsptr) { QString str; StateEvent se; return(se.linerun(curlsptr)) ; }** unsigned int StateEvent::linerun(struct linestatus *curlsptr) { Do Something !!! return(sechk(curlsptr)); } void StateEvent::runEventTable(QString today, QString text) { if((*StateEventTable[clss.event][clss.state])(&clss) < 0x3f) }
Mainwindow.h
#include <QMainWindow.h> #include "StateEvent.h" class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); Ui::MainWindow *ui; StateEvent seTable, *se = new StateEvent(); }
Mainwindow.cpp
#include "Mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::showTime); timer->start(10); } void MainWindow::showTime() { QDate date = QDate::currentDate(); QTime time = QTime::currentTime(); QString text,today; unsigned long milliseconds; today = date.toString("yy.MM.dd"); text = time.toString("hh:mm:ss.zzz"); seTable.runEventTable(today, text); }
-
My issue occurs when I am trying to call a member function in a non-member function that is used in a member array of functions in a state event table. I have included a lot of information below, but in essence if the array calls a nop() function or a p_wait function that only calls other non member functions , Every thing works. But if The array calls lrun() non-member function the program crashes with a segment error.
Does anyone have any ideas??
Thanksstateevent.h
extern unsigned int nop(struct linestatus *); extern unsigned int lrun(struct linestatus *); extern unsigned int p_wait(struct linestatus *); extern unsigned int sp_scrap(struct linestatus *); class StateEvent : public QDialog { Q_OBJECT public: explicit StateEvent( QWidget *parent = nullptr); ~StateEvent(); Ui::StateEvent *seui; event_handler StateEventTable[MEVENT][MSTATE] = { /*ev 0*/ {waite, lrun, nop, cont, }, /*ev 1*/ {nop, nop, nop, p_wait}, /*ev 2*/ {nop, nop, nop, nop, }, /*ev 3*/ {nop, sp_scrap, nop, nop} }; private: StateEvent sefunc(); };
stateevent.cpp
unsigned int p_wait(struct linestatus *curlsptr) { return(sechk(curlsptr)); } **unsigned int lrun(struct linestatus *curlsptr) { QString str; StateEvent se; return(se.linerun(curlsptr)) ; }** unsigned int StateEvent::linerun(struct linestatus *curlsptr) { Do Something !!! return(sechk(curlsptr)); } void StateEvent::runEventTable(QString today, QString text) { if((*StateEventTable[clss.event][clss.state])(&clss) < 0x3f) }
Mainwindow.h
#include <QMainWindow.h> #include "StateEvent.h" class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); Ui::MainWindow *ui; StateEvent seTable, *se = new StateEvent(); }
Mainwindow.cpp
#include "Mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QTimer *timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &MainWindow::showTime); timer->start(10); } void MainWindow::showTime() { QDate date = QDate::currentDate(); QTime time = QTime::currentTime(); QString text,today; unsigned long milliseconds; today = date.toString("yy.MM.dd"); text = time.toString("hh:mm:ss.zzz"); seTable.runEventTable(today, text); }
@dencla
Please post code like this inside proper code tags for this forum. You can see the definition of*unsigned int lrun(struct linestatus curlsptr)
has already been shown wrong, with italics and extra/missing
*
.Assuming that is not the issue, start by letting it segment error inside the debugger and determine what the cause of that is.