Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How do i integrate my embedded C source codes (for my embedded linux board) with Qt GUI together?
Forum Updated to NodeBB v4.3 + New Features

How do i integrate my embedded C source codes (for my embedded linux board) with Qt GUI together?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
33 Posts 4 Posters 9.0k Views 2 Watching
  • 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.
  • E Offline
    E Offline
    embdev
    wrote on 21 Sept 2016, 09:59 last edited by
    #1

    Suppose I've my existing C source codes to run on my embedded Linux board and i'd like to create a Qt GUI using e.g. QtWidget application. How do I exactly integrate the Qt GUI and C source codes together? e.g. if I create a GUI to playback video, how to link e.g. a [Open] button to trigger e.g. a video decoder block that will run on my embedded Linux?

    J 1 Reply Last reply 21 Sept 2016, 12:47
    0
    • E embdev
      21 Sept 2016, 09:59

      Suppose I've my existing C source codes to run on my embedded Linux board and i'd like to create a Qt GUI using e.g. QtWidget application. How do I exactly integrate the Qt GUI and C source codes together? e.g. if I create a GUI to playback video, how to link e.g. a [Open] button to trigger e.g. a video decoder block that will run on my embedded Linux?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 21 Sept 2016, 12:47 last edited by
      #2

      @embdev Read http://doc.qt.io/qt-5.7/signalsandslots.html
      C can be easily called from C++. You can simply add your C code to your Qt project. Or you can build your C code as a library and link it to your Qt application.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply 22 Sept 2016, 03:50
      2
      • J jsulm
        21 Sept 2016, 12:47

        @embdev Read http://doc.qt.io/qt-5.7/signalsandslots.html
        C can be easily called from C++. You can simply add your C code to your Qt project. Or you can build your C code as a library and link it to your Qt application.

        E Offline
        E Offline
        embdev
        wrote on 22 Sept 2016, 03:50 last edited by
        #3

        @jsulm I see, so more specifically on the implementation level, suppose I create a QtWidget application project, and I've the embedded hardware source codes, should it be a stand alone source page or I should merge inside, say in the mainwindow.cpp?

        J 1 Reply Last reply 22 Sept 2016, 04:17
        0
        • E embdev
          22 Sept 2016, 03:50

          @jsulm I see, so more specifically on the implementation level, suppose I create a QtWidget application project, and I've the embedded hardware source codes, should it be a stand alone source page or I should merge inside, say in the mainwindow.cpp?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 22 Sept 2016, 04:17 last edited by
          #4

          @embdev You should not merge it. What would be the benefit? Keep it separated from your UI code.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          E 1 Reply Last reply 22 Sept 2016, 06:23
          0
          • J jsulm
            22 Sept 2016, 04:17

            @embdev You should not merge it. What would be the benefit? Keep it separated from your UI code.

            E Offline
            E Offline
            embdev
            wrote on 22 Sept 2016, 06:23 last edited by
            #5

            @jsulm okies, so implementation level is that i'll have a UI source, then it'll call on to the functions in my embedded C code to execute certain features on my embedded Linux board.

            In that sense, my kit, especially my qmake.exe needs to be correctly setup so that when I build, the qmake.exe will build my C codes as well as the GUI codes using my compiler right?

            J 1 Reply Last reply 22 Sept 2016, 06:27
            0
            • E embdev
              22 Sept 2016, 06:23

              @jsulm okies, so implementation level is that i'll have a UI source, then it'll call on to the functions in my embedded C code to execute certain features on my embedded Linux board.

              In that sense, my kit, especially my qmake.exe needs to be correctly setup so that when I build, the qmake.exe will build my C codes as well as the GUI codes using my compiler right?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 22 Sept 2016, 06:27 last edited by
              #6

              @embdev No need to change anything in your kit. Just use .c suffix instead of .cpp for your C code the build system is smart enough to find out which compiler (gcc for C and g++ for C++) to call.
              You just need to add that C files to your .pro file as you do for C++ files.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              E 1 Reply Last reply 22 Sept 2016, 10:00
              1
              • J jsulm
                22 Sept 2016, 06:27

                @embdev No need to change anything in your kit. Just use .c suffix instead of .cpp for your C code the build system is smart enough to find out which compiler (gcc for C and g++ for C++) to call.
                You just need to add that C files to your .pro file as you do for C++ files.

                E Offline
                E Offline
                embdev
                wrote on 22 Sept 2016, 10:00 last edited by
                #7

                @jsulm got it. so suppose I've added my embedded Linux .c file and then I created a UI button, By using signals & slots feature in Qt, I can link the button to triggering a particular f(x) in my .c file to run some processes on my embedded Linux board. is this train of thought correct?

                J 1 Reply Last reply 22 Sept 2016, 10:51
                0
                • E embdev
                  22 Sept 2016, 10:00

                  @jsulm got it. so suppose I've added my embedded Linux .c file and then I created a UI button, By using signals & slots feature in Qt, I can link the button to triggering a particular f(x) in my .c file to run some processes on my embedded Linux board. is this train of thought correct?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 22 Sept 2016, 10:51 last edited by
                  #8

                  @embdev Yes, it is. Include the C header file where your C function is declared.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  E 2 Replies Last reply 23 Sept 2016, 00:40
                  2
                  • J jsulm
                    22 Sept 2016, 10:51

                    @embdev Yes, it is. Include the C header file where your C function is declared.

                    E Offline
                    E Offline
                    embdev
                    wrote on 23 Sept 2016, 00:40 last edited by
                    #9

                    @jsulm greatly appreciate for the directions! I'll try it out!

                    1 Reply Last reply
                    0
                    • J jsulm
                      22 Sept 2016, 10:51

                      @embdev Yes, it is. Include the C header file where your C function is declared.

                      E Offline
                      E Offline
                      embdev
                      wrote on 26 Sept 2016, 06:24 last edited by
                      #10

                      @jsulm suppose I've created a QtWidget project with main.cpp and mainwindow.cpp sources created. I've also created a simple UI with pushButton to run a particular f(x) in another source code (that access my embedded Linux target directly)

                      #include "mainwindow.h"
                      #include "ui_mainwindow.h"

                      MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      }

                      MainWindow::~MainWindow()
                      {
                      delete ui;
                      }

                      void MainWindow::on_pushButton_clicked()
                      {

                      SAMPLE_VDEC_VdhH264();
                      

                      }

                      The SAMPLE_VDEC_VdhH264(); is actually defined in my embedded source code as one of the options. Is it okay to add the function just like that? as I met with build error saying that that function is not declared in this scope.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 26 Sept 2016, 06:28 last edited by mrjj
                        #11

                        Hi
                        You need to include the header file also

                        #include "VDEC_VdhH264.H" or where ever
                        SAMPLE_VDEC_VdhH264()
                        is declared.

                        E 1 Reply Last reply 26 Sept 2016, 06:47
                        2
                        • M mrjj
                          26 Sept 2016, 06:28

                          Hi
                          You need to include the header file also

                          #include "VDEC_VdhH264.H" or where ever
                          SAMPLE_VDEC_VdhH264()
                          is declared.

                          E Offline
                          E Offline
                          embdev
                          wrote on 26 Sept 2016, 06:47 last edited by embdev
                          #12

                          @mrjj I see. Well, because I've a main.c source file from vendor as sample program, which I've also added into Qt projects. And i'd like to link pushbutton I've created in mainwindow.mpp source file to link to my vendor sample source file function [i.e. SAMPLE_VDEC_VdhH264(); ], Hence there's no header file for the high-level function, as the high-level function is defined in the sample source file.

                          Does it mean I've to create a separate header file to include the high-level functions in the sample source file, so that I can add the header file into mainwindow.mpp, containing the high-level function defined in my sample source file, and that I can then just call the functions accordingly?

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 26 Sept 2016, 06:50 last edited by mrjj
                            #13

                            Hi
                            I would make a new .h file for it as not to be messy.
                            This file would list the functions from main.c

                            However, if the main.cpp is included in the project, you can use without .h file like this

                            void/int SAMPLE_VDEC_VdhH264(); //// forward declare it

                            void MainWindow::on_pushButton_clicked()
                            {
                            SAMPLE_VDEC_VdhH264(); // call it
                            }

                            E 1 Reply Last reply 26 Sept 2016, 08:53
                            0
                            • M mrjj
                              26 Sept 2016, 06:50

                              Hi
                              I would make a new .h file for it as not to be messy.
                              This file would list the functions from main.c

                              However, if the main.cpp is included in the project, you can use without .h file like this

                              void/int SAMPLE_VDEC_VdhH264(); //// forward declare it

                              void MainWindow::on_pushButton_clicked()
                              {
                              SAMPLE_VDEC_VdhH264(); // call it
                              }

                              E Offline
                              E Offline
                              embdev
                              wrote on 26 Sept 2016, 08:53 last edited by
                              #14

                              @mrjj I've included the headers from my sample source file in main.mpp as well, with the SAMPLE_VDEC_VdhH264 function declaration.

                              In mainwindow.cpp

                              #include "mainwindow.h"
                              #include <QApplication>

                              #include <stdio.h>
                              #include <stdlib.h>
                              #include <string.h>
                              #include <sys/types.h>
                              #include <sys/stat.h>
                              #include <sys/ioctl.h>
                              #include <sys/poll.h>
                              #include <sys/time.h>
                              #include <fcntl.h>
                              #include <errno.h>
                              #include <pthread.h>
                              #include <math.h>
                              #include <unistd.h>
                              #include <signal.h>
                              #include "sample_comm.h"

                              int main(int argc, char *argv[])
                              {
                              QApplication a(argc, argv);
                              MainWindow w;
                              w.show();

                              int SAMPLE_VDEC_VdhH264();
                              
                              return a.exec();
                              

                              }

                              In mainwindow.cpp, invoke the function SAMPLE_VDEC_VdhH264

                              #include "mainwindow.h"
                              #include "ui_mainwindow.h"

                              MainWindow::MainWindow(QWidget *parent) :
                              QMainWindow(parent),
                              ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);
                              }

                              MainWindow::~MainWindow()
                              {
                              delete ui;
                              }

                              void MainWindow::on_pushButton_clicked()
                              {

                              SAMPLE_VDEC_VdhH264();

                              }


                              I tried to build again but it says the same error though (i.e. in mainwindow.cpp, 'SAMPLE_VDEC_VdhH264 was not declared in this scope')

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 26 Sept 2016, 08:56 last edited by mrjj
                                #15

                                int main(int argc, char *argv[])
                                {
                                QApplication a(argc, argv);
                                MainWindow w;
                                w.show();

                                int SAMPLE_VDEC_VdhH264(); <<<< why here??? that is forward in main. not what i ment.

                                return a.exec();
                                }

                                Did you make a .h file with ?
                                int SAMPLE_VDEC_VdhH264();

                                else
                                i mean like

                                int SAMPLE_VDEC_VdhH264();

                                void MainWindow::on_pushButton_clicked()
                                {

                                SAMPLE_VDEC_VdhH264();

                                }

                                E 1 Reply Last reply 26 Sept 2016, 09:42
                                0
                                • M mrjj
                                  26 Sept 2016, 08:56

                                  int main(int argc, char *argv[])
                                  {
                                  QApplication a(argc, argv);
                                  MainWindow w;
                                  w.show();

                                  int SAMPLE_VDEC_VdhH264(); <<<< why here??? that is forward in main. not what i ment.

                                  return a.exec();
                                  }

                                  Did you make a .h file with ?
                                  int SAMPLE_VDEC_VdhH264();

                                  else
                                  i mean like

                                  int SAMPLE_VDEC_VdhH264();

                                  void MainWindow::on_pushButton_clicked()
                                  {

                                  SAMPLE_VDEC_VdhH264();

                                  }

                                  E Offline
                                  E Offline
                                  embdev
                                  wrote on 26 Sept 2016, 09:42 last edited by embdev
                                  #16

                                  @mrjj my apologies, I've read it otherwise. However, it seems that the compiler can't find my function definition. It's a separate source code which I've added into the project entitled "sample_vdec.c". The function definition in this source code is:

                                  HI_S32 SAMPLE_VDEC_VdhH264(HI_VOID)
                                  {
                                  ....................
                                  }

                                  I've amended to the following:

                                  in mainwindow.cpp:

                                  #include "mainwindow.h"
                                  #include "ui_mainwindow.h"
                                  #include "hi3536mainfx.h"

                                  MainWindow::MainWindow(QWidget *parent) :
                                  QMainWindow(parent),
                                  ui(new Ui::MainWindow)
                                  {
                                  ui->setupUi(this);
                                  }

                                  MainWindow::~MainWindow()
                                  {
                                  delete ui;
                                  }

                                  HI_U32 SAMPLE_VDEC_VdhH264();

                                  void MainWindow::on_pushButton_clicked()
                                  {

                                  SAMPLE_VDEC_VdhH264();

                                  }

                                  in main.cpp

                                  #include "mainwindow.h"
                                  #include <QApplication>

                                  int main(int argc, char *argv[])
                                  {
                                  QApplication a(argc, argv);
                                  MainWindow w;
                                  w.show();

                                  return a.exec();
                                  

                                  }

                                  in header

                                  #ifndef HI3536MAINFX_H
                                  #define HI3536MAINFX_H
                                  #include <hi_type.h>
                                  #include <hi_comm_vb.h>

                                  typedef struct hiVDEC_USERPIC_S
                                  {
                                  HI_U32 u32PicWidth;
                                  HI_U32 u32PicHeigth;
                                  VB_POOL u32PoolId;
                                  VB_BLK u32BlkHandle;
                                  HI_U32 u32PhyAddr;
                                  HI_VOID *pVirAddr;
                                  }VDEC_USERPIC_S;

                                  HI_U32 SAMPLE_VDEC_VdhH264();

                                  #endif // HI3536MAINFX_H

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 26 Sept 2016, 10:00 last edited by
                                    #17

                                    since you have a
                                    HI3536MAINFX_H
                                    with
                                    HI_U32 SAMPLE_VDEC_VdhH264();

                                    you dont need it over
                                    void MainWindow::on_pushButton_clicked()
                                    also.

                                    so compiles now?

                                    E 1 Reply Last reply 27 Sept 2016, 01:46
                                    0
                                    • M mrjj
                                      26 Sept 2016, 10:00

                                      since you have a
                                      HI3536MAINFX_H
                                      with
                                      HI_U32 SAMPLE_VDEC_VdhH264();

                                      you dont need it over
                                      void MainWindow::on_pushButton_clicked()
                                      also.

                                      so compiles now?

                                      E Offline
                                      E Offline
                                      embdev
                                      wrote on 27 Sept 2016, 01:46 last edited by embdev
                                      #18

                                      @mrjj discovered some error in datatype in my code but rectified it but still unable to compile. The error says undefined reference to SAMPLE_VDEC_VhdH264(); and ld returned 1 exit status.
                                      When I highlighted VDEC_SAMPLEVhdH264(); in main.cpp and hit [F2] cursor recursively, it brings me to the sample source code where this function is defined but doesn't brings me to the header where I declared this function.

                                      ** in main.cpp **

                                      #include "mainwindow.h"
                                      #include "ui_mainwindow.h"
                                      #include "hi3536mainfx.h"
                                      
                                      MainWindow::MainWindow(QWidget *parent) :
                                          QMainWindow(parent),
                                          ui(new Ui::MainWindow)
                                      {
                                          ui->setupUi(this);
                                      }
                                      
                                      MainWindow::~MainWindow()
                                      {
                                          delete ui;
                                      }
                                      
                                      
                                      void MainWindow::on_pushButton_clicked()
                                      {
                                      
                                         SAMPLE_VDEC_VdhH264();
                                      
                                      }
                                      

                                      ** in sample source code where SAMPLE_VDEC_VhdH264() is defined: **

                                      HI_S32 SAMPLE_VDEC_VdhH264(HI_VOID)
                                      {
                                          VB_CONF_S stVbConf, stModVbConf;
                                          HI_S32 i, s32Ret = HI_SUCCESS;
                                          VDEC_CHN_ATTR_S stVdecChnAttr[VDEC_MAX_CHN_NUM];
                                          VdecThreadParam stVdecSend[VDEC_MAX_CHN_NUM];
                                          VPSS_GRP_ATTR_S stVpssGrpAttr[VDEC_MAX_CHN_NUM];
                                       ..... ..... .....
                                      }
                                      

                                      ** in my header file **

                                      #ifndef HI3536MAINFX_H
                                      #define HI3536MAINFX_H
                                      #include "hi_comm_vb.h"
                                      #include "hi_type.h"
                                      
                                      typedef struct hiVDEC_USERPIC_S
                                      {
                                          HI_U32   u32PicWidth;
                                          HI_U32   u32PicHeigth;
                                          VB_POOL  u32PoolId;
                                          VB_BLK   u32BlkHandle;
                                          HI_U32   u32PhyAddr;
                                          HI_VOID  *pVirAddr;
                                      }VDEC_USERPIC_S;
                                      
                                      HI_S32 SAMPLE_VDEC_VdhH264(HI_VOID);
                                      
                                      #endif // HI3536MAINFX_H
                                      
                                      J 1 Reply Last reply 27 Sept 2016, 04:49
                                      0
                                      • E embdev
                                        27 Sept 2016, 01:46

                                        @mrjj discovered some error in datatype in my code but rectified it but still unable to compile. The error says undefined reference to SAMPLE_VDEC_VhdH264(); and ld returned 1 exit status.
                                        When I highlighted VDEC_SAMPLEVhdH264(); in main.cpp and hit [F2] cursor recursively, it brings me to the sample source code where this function is defined but doesn't brings me to the header where I declared this function.

                                        ** in main.cpp **

                                        #include "mainwindow.h"
                                        #include "ui_mainwindow.h"
                                        #include "hi3536mainfx.h"
                                        
                                        MainWindow::MainWindow(QWidget *parent) :
                                            QMainWindow(parent),
                                            ui(new Ui::MainWindow)
                                        {
                                            ui->setupUi(this);
                                        }
                                        
                                        MainWindow::~MainWindow()
                                        {
                                            delete ui;
                                        }
                                        
                                        
                                        void MainWindow::on_pushButton_clicked()
                                        {
                                        
                                           SAMPLE_VDEC_VdhH264();
                                        
                                        }
                                        

                                        ** in sample source code where SAMPLE_VDEC_VhdH264() is defined: **

                                        HI_S32 SAMPLE_VDEC_VdhH264(HI_VOID)
                                        {
                                            VB_CONF_S stVbConf, stModVbConf;
                                            HI_S32 i, s32Ret = HI_SUCCESS;
                                            VDEC_CHN_ATTR_S stVdecChnAttr[VDEC_MAX_CHN_NUM];
                                            VdecThreadParam stVdecSend[VDEC_MAX_CHN_NUM];
                                            VPSS_GRP_ATTR_S stVpssGrpAttr[VDEC_MAX_CHN_NUM];
                                         ..... ..... .....
                                        }
                                        

                                        ** in my header file **

                                        #ifndef HI3536MAINFX_H
                                        #define HI3536MAINFX_H
                                        #include "hi_comm_vb.h"
                                        #include "hi_type.h"
                                        
                                        typedef struct hiVDEC_USERPIC_S
                                        {
                                            HI_U32   u32PicWidth;
                                            HI_U32   u32PicHeigth;
                                            VB_POOL  u32PoolId;
                                            VB_BLK   u32BlkHandle;
                                            HI_U32   u32PhyAddr;
                                            HI_VOID  *pVirAddr;
                                        }VDEC_USERPIC_S;
                                        
                                        HI_S32 SAMPLE_VDEC_VdhH264(HI_VOID);
                                        
                                        #endif // HI3536MAINFX_H
                                        
                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 27 Sept 2016, 04:49 last edited by
                                        #19

                                        @embdev said in How do i integrate my embedded C source codes (for my embedded linux board) with Qt GUI together?:

                                        in sample source code where SAMPLE_VDEC_VhdH264() is defined:

                                        Is the source file containing SAMPLE_VDEC_VhdH264() part of your project and is it built?

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        E 1 Reply Last reply 27 Sept 2016, 06:46
                                        0
                                        • J jsulm
                                          27 Sept 2016, 04:49

                                          @embdev said in How do i integrate my embedded C source codes (for my embedded linux board) with Qt GUI together?:

                                          in sample source code where SAMPLE_VDEC_VhdH264() is defined:

                                          Is the source file containing SAMPLE_VDEC_VhdH264() part of your project and is it built?

                                          E Offline
                                          E Offline
                                          embdev
                                          wrote on 27 Sept 2016, 06:46 last edited by
                                          #20

                                          @jsulm yes it is, the source file containing the function definition SAMPLE_VDEC_VhdH264() is added physically into the project file.

                                          J 1 Reply Last reply 27 Sept 2016, 06:56
                                          0

                                          3/33

                                          22 Sept 2016, 03:50

                                          topic:navigator.unread, 30
                                          • Login

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