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. invalid use of non-static member function
Forum Updated to NodeBB v4.3 + New Features

invalid use of non-static member function

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 3.8k Views 1 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.
  • A Offline
    A Offline
    aqdam
    wrote on last edited by
    #1

    Hi all,
    i build a qt-app to run my program(capture program to take picture using v4l2 and entire code is in c) and show the captured photo using qt-widgets,so in qt-app i used qprocess to run my program, i finished it.
    now i want to write qt-app which will take pic using my c code which is in c without using qprocess, so i thought of creating my entire program's shared library and use its functions(written in c) to take picture and show.
    from the following steps i added my program as shared library...
    http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

    #-------------------------------------------------

    Project created by QtCreator 2017-11-08T12:09:02

    #-------------------------------------------------

    //qt-app.pro

     QT       += core gui multimedia multimediawidgets
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = qt_app
    TEMPLATE = app
    SOURCES += \
            main.cpp \
            mainwindow.cpp
    
    HEADERS += \
            mainwindow.h#INCLUDEPATH += /u/cam_prog1/Include
    
    
    FORMS += \
            mainwindow.ui
    
    unix:!macx: LIBS += -L$$PWD/../../u/cam_prog1/Library/ -lcam1
    
    INCLUDEPATH += $$PWD/../../u/cam_prog1/Include
    DEPENDPATH += $$PWD/../../u/cam_prog1/Include
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QDebug>
    #include <QProcess>
    #include <QCameraViewfinder>
    #include <QMessageBox>
    
    QString file_name,img_path="/u/images/",X,Y,s,br,ct,st,sh,rotate,effects,fr;
    int brig,cont,sat,sharp,frames;
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        s = "/u/cam_prog1/Output/cam_main.out";
        qDebug() << s;
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    void MainWindow::on_pushButton_5_clicked()
    {
        QStringList args;
        QProcess *process = new QProcess(this);
        camera->stop();
        file_name = ui->lineEdit_6->text();
    
        if((frames = ui->spinBox->value()) == 0)
            frames = 10;
        if((brig = ui->spinBox_2->value()) == 0)
            brig = 100;
        if((cont = ui->spinBox_3->value()) == 0)
            cont = 100;
        if((sat = ui->spinBox_4->value()) == 0)
            sat = 100;
        if((sharp = ui->spinBox_5->value()) == 0)
            sharp = 100;
        if(ui->radioButton->isChecked())
            rotate = 90;
        if(((X = ui->lineEdit_4->text()) == '\0') || (  (Y = ui->lineEdit_5->text()) == '\0'))
        {
            X = "640";   Y = "480";
        }
    
        br = QString::number(brig);
        ct = QString::number(cont);
        st = QString::number(sat);
        sh = QString::number(sharp);
        rotate = ui->comboBox->currentText();
        effects = ui->comboBox_2->currentText();
        fr = QString::number(frames);
        file_name = img_path + file_name;
        args << X << Y << fr << file_name << "B" << br << "C" << ct << "S" << st << "R" << rotate << "N" << sh << "V" << "E" << effects;
        process->start( s, args);
        QPixmap b(file_name);
        ui->label_6->setPixmap(b.scaled(ui->label_6->width(),ui->label_6->height()));
    }
    
    void MainWindow::on_pushButton_6_clicked()
    {
            this->close();
    }
    
    void MainWindow::on_pushButton_4_clicked()
    {
        void * ptr;
        file_name = ui->lineEdit_6->text();
        file_name = img_path + file_name;
        convert_jpeg(file_name,ptr,x,y,x,y);
        QPixmap b(file_name);
        ui->label_6->setPixmap(b.scaled(ui->label_6->width(),ui->label_6->height()));
    }
    
    
    void MainWindow::on_pushButton_clicked()
    {
        if (QCameraInfo::availableCameras().count() > 0)
                {
                    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
                    foreach (const QCameraInfo &cameraInfo, cameras) {
                        if (cameraInfo == QCameraInfo::defaultCamera())
                           camera= new QCamera(cameraInfo);
                        }
                }
                else
                {
                    QMessageBox::warning(this, tr("Error"), tr("No Camera is available."));
                   // QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
                }
                camera->setViewfinder(ui->viewfinder);
                ui->stackedWidget->setCurrentIndex(0);
                camera->start();
    }
    

    here i want to use my library funtion as
    convert_jpeg(file_name,ptr,x,y,x,y);

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QCamera>
    #include <QCameraImageCapture>
    #include <QCameraInfo>
    
    extern "C"{
    #include "/u/cam_prog1/Include/cam_main.h"
    }
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private slots:
    
        void on_pushButton_6_clicked();
    
        void on_pushButton_5_clicked();
    
        void on_pushButton_4_clicked();
    
        void on_pushButton_clicked();
    
    private:
        Ui::MainWindow *ui;
        QCamera * camera;
    };
    
    #endif // MAINWINDOW_H
    
    

    now when i run this above program i'm getting the following error...

    /root/qt_app_1_0/mainwindow.cpp:80: error: invalid use of non-static member function
         convert_jpeg(file_name,ptr,x,y,x,y);
                                           ^
    

    quick respose would be appreciated
    thanks

    aha_1980A 1 Reply Last reply
    0
    • A aqdam

      Hi all,
      i build a qt-app to run my program(capture program to take picture using v4l2 and entire code is in c) and show the captured photo using qt-widgets,so in qt-app i used qprocess to run my program, i finished it.
      now i want to write qt-app which will take pic using my c code which is in c without using qprocess, so i thought of creating my entire program's shared library and use its functions(written in c) to take picture and show.
      from the following steps i added my program as shared library...
      http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html

      #-------------------------------------------------

      Project created by QtCreator 2017-11-08T12:09:02

      #-------------------------------------------------

      //qt-app.pro

       QT       += core gui multimedia multimediawidgets
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = qt_app
      TEMPLATE = app
      SOURCES += \
              main.cpp \
              mainwindow.cpp
      
      HEADERS += \
              mainwindow.h#INCLUDEPATH += /u/cam_prog1/Include
      
      
      FORMS += \
              mainwindow.ui
      
      unix:!macx: LIBS += -L$$PWD/../../u/cam_prog1/Library/ -lcam1
      
      INCLUDEPATH += $$PWD/../../u/cam_prog1/Include
      DEPENDPATH += $$PWD/../../u/cam_prog1/Include
      

      mainwindow.cpp

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QDebug>
      #include <QProcess>
      #include <QCameraViewfinder>
      #include <QMessageBox>
      
      QString file_name,img_path="/u/images/",X,Y,s,br,ct,st,sh,rotate,effects,fr;
      int brig,cont,sat,sharp,frames;
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          s = "/u/cam_prog1/Output/cam_main.out";
          qDebug() << s;
      
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      
      void MainWindow::on_pushButton_5_clicked()
      {
          QStringList args;
          QProcess *process = new QProcess(this);
          camera->stop();
          file_name = ui->lineEdit_6->text();
      
          if((frames = ui->spinBox->value()) == 0)
              frames = 10;
          if((brig = ui->spinBox_2->value()) == 0)
              brig = 100;
          if((cont = ui->spinBox_3->value()) == 0)
              cont = 100;
          if((sat = ui->spinBox_4->value()) == 0)
              sat = 100;
          if((sharp = ui->spinBox_5->value()) == 0)
              sharp = 100;
          if(ui->radioButton->isChecked())
              rotate = 90;
          if(((X = ui->lineEdit_4->text()) == '\0') || (  (Y = ui->lineEdit_5->text()) == '\0'))
          {
              X = "640";   Y = "480";
          }
      
          br = QString::number(brig);
          ct = QString::number(cont);
          st = QString::number(sat);
          sh = QString::number(sharp);
          rotate = ui->comboBox->currentText();
          effects = ui->comboBox_2->currentText();
          fr = QString::number(frames);
          file_name = img_path + file_name;
          args << X << Y << fr << file_name << "B" << br << "C" << ct << "S" << st << "R" << rotate << "N" << sh << "V" << "E" << effects;
          process->start( s, args);
          QPixmap b(file_name);
          ui->label_6->setPixmap(b.scaled(ui->label_6->width(),ui->label_6->height()));
      }
      
      void MainWindow::on_pushButton_6_clicked()
      {
              this->close();
      }
      
      void MainWindow::on_pushButton_4_clicked()
      {
          void * ptr;
          file_name = ui->lineEdit_6->text();
          file_name = img_path + file_name;
          convert_jpeg(file_name,ptr,x,y,x,y);
          QPixmap b(file_name);
          ui->label_6->setPixmap(b.scaled(ui->label_6->width(),ui->label_6->height()));
      }
      
      
      void MainWindow::on_pushButton_clicked()
      {
          if (QCameraInfo::availableCameras().count() > 0)
                  {
                      QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
                      foreach (const QCameraInfo &cameraInfo, cameras) {
                          if (cameraInfo == QCameraInfo::defaultCamera())
                             camera= new QCamera(cameraInfo);
                          }
                  }
                  else
                  {
                      QMessageBox::warning(this, tr("Error"), tr("No Camera is available."));
                     // QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);
                  }
                  camera->setViewfinder(ui->viewfinder);
                  ui->stackedWidget->setCurrentIndex(0);
                  camera->start();
      }
      

      here i want to use my library funtion as
      convert_jpeg(file_name,ptr,x,y,x,y);

      mainwindow.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QCamera>
      #include <QCameraImageCapture>
      #include <QCameraInfo>
      
      extern "C"{
      #include "/u/cam_prog1/Include/cam_main.h"
      }
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
      
      private slots:
      
          void on_pushButton_6_clicked();
      
          void on_pushButton_5_clicked();
      
          void on_pushButton_4_clicked();
      
          void on_pushButton_clicked();
      
      private:
          Ui::MainWindow *ui;
          QCamera * camera;
      };
      
      #endif // MAINWINDOW_H
      
      

      now when i run this above program i'm getting the following error...

      /root/qt_app_1_0/mainwindow.cpp:80: error: invalid use of non-static member function
           convert_jpeg(file_name,ptr,x,y,x,y);
                                             ^
      

      quick respose would be appreciated
      thanks

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @aqdam,

      You didn't provide the most important thing: the function definition of convert_jpeg. I guess it's a function within a class?

      quick respose would be appreciated

      This is a user to user forum. People helping in their spare time and for free. Be nice to them ;)

      Qt has to stay free or it will die.

      A 1 Reply Last reply
      3
      • aha_1980A aha_1980

        Hi @aqdam,

        You didn't provide the most important thing: the function definition of convert_jpeg. I guess it's a function within a class?

        quick respose would be appreciated

        This is a user to user forum. People helping in their spare time and for free. Be nice to them ;)

        A Offline
        A Offline
        aqdam
        wrote on last edited by
        #3

        @aha_1980
        thanks for your reply,
        the function convert_jpeg() is there in the my library(whose path i gave).
        i think the problem is that library which gave is dynamic.
        i dont know to how to proceed further?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          It has nothing to do with the type of library you are using.

          You didn't answer @aha_1980's question: is convert_jpeg part of a class or maybe a namespace ?

          The error states that you are trying to use it like a free function and it's not the case of convert_jpeg .

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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