invalid use of non-static member function
-
wrote on 12 Jan 2018, 11:34 last edited by
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 += 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 -
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 += 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
thanksHi @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 ;)
-
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 ;)
-
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
.
1/4