第一次使用qt不确定我的问题是它的未定义参考错误

时间:2019-05-24 19:56:12

标签: c++ qt user-interface camera

userinterface.pro

#-------------------------------------------------
#
# Project created by QtCreator 2019-05-22T16:09:30
#
#-------------------------------------------------

QT       += core gui multimedia multimediawidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = interface
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += main.cpp \
        mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui

QMAKE_CXXFLAGS += -std=gnu++14
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>



namespace Ui {
class MainWindow;
}
class QCamera;
class QCameraViewfinder;
class QCameraImageCapture;
class QVBoxLayout;
class QMenu;
class QAction;

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();

private:
Ui::MainWindow *ui;
QCamera *mCamera;
QCameraViewfinder *mCameraViewfinder;
QCameraImageCapture *mCameraImageCapture;
QVBoxLayout *mLayout;
QMenu *mOptionsMenu;
QAction *mOnAction;
QAction *mDeleteAction;
QAction *mCaptureAction;
};

#endif // MAINWINDOW_H

main.cpp

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

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;                       //ERROR IS ON THIS LINE
        w.show();

        return a.exec();
    }

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraViewfinderSettings>
#include <QCameraImageCapture>
#include <QVBoxLayout>
#include <QMenu>
#include <QAction>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
:   QMainWindow(parent)
,   ui(new Ui::MainWindow)
{
ui->setupUi(this);
mCamera = new QCamera(this);
mCameraViewfinder = new QCameraViewfinder(this);
mCameraImageCapture = new QCameraImageCapture(mCamera, this);
mLayout = new QVBoxLayout;
mOptionsMenu = new QMenu("Options",this);
mOnAction = new QAction("On", this);
mDeleteAction = new QAction("Delete",this);
mCaptureAction = new QAction("Capture",this);
mOptionsMenu->addActions({mOnAction,mDeleteAction,
                          mCaptureAction});
ui->optionsPushButton->setMenu(mOptionsMenu);
mCamera->setViewfinder(mCameraViewfinder);
mLayout->addWidget(mCameraViewfinder);
mLayout->setMargin(0);
ui->scrollArea->setLayout(mLayout);
connect(mOnAction, &QAction::triggered,[&](){
    mCamera->start();
});
connect(mDeleteAction, &QAction::triggered,[&](){
    mCamera->stop();
});
connect(mCaptureAction, &QAction::triggered, [&](){
   auto filename = QFileDialog::getSaveFileName(this,"Capture","/",
                       "Imagen (*.jpg;*).jpeg)");
   if(filename.isEmpty()){
       return;
   }
    mCameraImageCapture->setCaptureDestination(
                QCameraImageCapture::CaptureToFile);
    QImageEncoderSettings imageEnCoderSettings;
    imageEnCoderSettings.setCodec("image/jpeg");
    imageEnCoderSettings.setResolution(1600,1200);
    mCameraImageCapture->setEncodingSettings(imageEnCoderSettings);
    mCamera->setCaptureMode(QCamera::CaptureStillImage);
    mCamera->start();
    mCamera->searchAndLock();
    mCameraImageCapture->capture(filename);
    mCamera->unlock();

});




}

我在umbunto 16的虚拟机上使用qt社区5.9.1 尝试运行程序时收到的错误消息如下: /home/brian/userinterface/main.cpp:7:错误:未定义对`MainWindow :: ~~ MainWindow()'的引用

/home/brian/userinterface/main.cpp:7:错误:未定义对`MainWindow :: ~~ MainWindow()'的引用

/home/brian/build-userinterface-Desktop_Qt_5_9_1_GCC_64bit-Debug/moc_mainwindow.o:-1:错误:未定义对`MainWindow ::〜MainWindow()'的引用

/home/brian/build-userinterface-Desktop_Qt_5_9_1_GCC_64bit-Debug/moc_mainwindow.o:-1:错误:未定义对`MainWindow ::〜MainWindow()'的引用

/home/brian/build-userinterface-Desktop_Qt_5_9_1_GCC_64bit-Debug/moc_mainwindow.o:-1:错误:未定义对`MainWindow的非虚拟重击的引用::〜MainWindow()'

/home/brian/build-userinterface-Desktop_Qt_5_9_1_GCC_64bit-Debug/moc_mainwindow.o:-1:错误:未定义对`MainWindow的非虚拟重击的引用::〜MainWindow()'

:-1:错误:collect2:错误:ld返回1个退出状态

0 个答案:

没有答案