Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling a class function from an class array of non class functions.
Forum Update on Monday, May 27th 2025

Calling a class function from an class array of non class functions.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 192 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dencla
    wrote on 6 Aug 2022, 02:20 last edited by Chris Kawa 8 Jun 2022, 13:57
    #1

    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??
    Thanks

    stateevent.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);
    }
    
    J 1 Reply Last reply 6 Aug 2022, 07:20
    0
    • D dencla
      6 Aug 2022, 02:20

      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??
      Thanks

      stateevent.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);
      }
      
      J Offline
      J Offline
      JonB
      wrote on 6 Aug 2022, 07:20 last edited by JonB 8 Jun 2022, 07:20
      #2

      @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.

      1 Reply Last reply
      1

      1/2

      6 Aug 2022, 02:20

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved