no such file or directory [duplicate] - c++

This question already has an answer here:
no such file or directory
(1 answer)
Closed 2 years ago.
i'm trying to get the image from my webcam using qt, opencv
here's my codes:
.pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2013-12-20T07:42:20
#
#-------------------------------------------------
QT += core gui
TARGET = QtCvCapture
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
imagecapture.cpp \
moc_imagecapture.cpp \
moc_mainwindow.cpp
HEADERS += mainwindow.h \
imagecapture.h \
ui_mainwindow.h
FORMS += mainwindow.ui
#include opencv for PC x86
#INCLUDEPATH += /usr/local/include/opencv
#LIBS +=/usr/local/lib/*.so
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv\release\bin\libopencv_core451.dll
LIBS += C:\opencv\release\bin\libopencv_highgui451.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs451.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc451.dll
LIBS += C:\opencv\release\bin\libopencv_features2d451.dll
LIBS += C:\opencv\release\bin\libopencv_calib3d451.dll
#include opencv for ARM
#INCLUDEPATH += /opt/opencv.arm/include/opencv
#LIBS += /opt/opencv.arm/lib/*.so
imagecapture.h:
#ifndef IMAGECAPTURE_H
#define IMAGECAPTURE_H
#include <QObject>
#include <QImage>
#include <QTimer>
#include <cv.h>
#include <highgui.h>
class ImageCapture : public QObject
{
Q_OBJECT
public:
explicit ImageCapture(QObject *parent = 0);
~ImageCapture();
signals:
public slots:
//!< attempts to start camera, camera number is given in cameraIndex (see cvCaptureFromCAM docs)
void captureFromCamera( int cameraIndex = -1 ); //index = -1 to capture form any camera
void stopCapture(); //!< stops timer and release OpenCV capture structure
protected:
QImage convert(IplImage * image); //!< create QImage from OpenCV image data
QImage IplImage2QImage(const IplImage *iplImage);
protected slots:
void timer_stick(); //!< grab and send frame on each timer tick
signals:
void imageCaptured( const QImage& image );
void error( const QString& text );
protected:
QTimer * _timer; //!< timeout signal is used to capture frames at regular intervals (or whenever possible in case of camera)
CvCapture * _cvCap; //!< used to grab image data from video or camera
IplImage* imagerd;
};
#endif // IMAGECAPTURE_H
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <imagecapture.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void on_actionOpen_Camera_triggered();
void displayImage(const QImage &image);
protected slots:
void captureError(const QString &text);
public:
ImageCapture *_capture;
};
#endif // MAINWINDOW_H
(i don't know if this kind of presentation is acceptable, i haven't seen anyone doing it yet)
the problems are:
C:\Users\FPT Shop\Downloads\QtCvCapture\QtCvCapture\mainwindow.h:4: error: QMainWindow: No such file
or directory
In file included from ..\QtCvCapture\mainwindow.cpp:1:
..\QtCvCapture\mainwindow.h:4:10: fatal error: QMainWindow: No such file or directory
same issues for cv.h and QtGUI/QApplicaiton, this happended when i try to #include them
what I have done: I have installed OpenCV and CMake following the instruction in https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows#OpenCV
the installation was successful, after which I compiled the program, then I'm met with the errors above. I have recheck and the files that the compiler claimed to be missing are there, in the folder (which I have linked in the .pro file). I found some answer said that it could be because my code is outdated? which I found reasonable because the code that's I'm using was published wayy back in 2013... sooo
what do you guys think?

Related

C++ Octave in QtCreator (windows)

I am trying to use Octave with Qt creator on Windows but I don't no why i can't succeed to link this library on this OS. I already tried on Ubuntu and everything works so i am a little bit lost...
I have octave3.6.4 (gcc 4.6.2) and i use the compiler gcc4.6.2 with Qt Creator.
my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-26T11:35:00
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
LIBS += -L$$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/lib/octave/3.6.4/ -loctave -loctinterp -lcruft
INCLUDEPATH += $$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/include
DEPENDPATH += $$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/include
PRE_TARGETDEPS += $$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/lib/octave/3.6.4/libcruft.dll.a
PRE_TARGETDEPS += $$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/lib/octave/3.6.4/liboctave.dll.a
PRE_TARGETDEPS += $$PWD/../../../../Octave/Octave3.6.4_gcc4.6.2/lib/octave/3.6.4/liboctinterp.dll.a
my .h file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <octave-3.6.4/octave/oct.h>
#include <octave-3.6.4/octave/octave.h>
#include <octave-3.6.4/octave/parse.h>
#include <octave-3.6.4/octave/toplev.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
And i have many link errors such as C2144 syntax error ...

Qtcreator can't find the class header file after promoting a widget to that class?

I'm a newbie in Qt and not that much experienced in C++ either.
I created simple Qt GUI app, but then I had to add the mousepressevent function on a QLabel type object, so I created the class which has the header file with following code:
#ifndef IMAGEACTION_H
#define IMAGEACTION_H
#include <QLabel>
#include <QMouseEvent>
#include <QDebug>
#include <QEvent>
class imageaction : public QLabel
{
Q_OBJECT
public:
explicit imageaction(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *ev);
signals:
void Mouse_Pressed();
public slots:
};
#endif // IMAGEACTION_H
The .cpp file has the following code:
#include "imageaction.h"
imageaction::imageaction(QWidget *parent) :
QLabel(parent)
{
}
void imageaction::mousePressEvent(QMouseEvent *ev)
{
emit Mouse_Pressed();
}
In the mainwindow.cpp file added the line #include "imageaction.h" to include the header file and in the .pro file it's the following lines are also added:
SOURCES += main.cpp\
mainwindow.cpp \
imageaction.cpp
HEADERS += mainwindow.h \
imageaction.h
But the program always gives the following error:
C1083: Cannot open include file:'imageaction.h': No such file or directory.
Could you say where I'm making the mistake? To make this class I followed this video
I think, "C1083: Cannot open include file:'imageaction.h': No such file or directory" error from your ui_*.h file. If that is the case, your issue regading promoting imageaction widget.
This may work
1. while promoting imageaction widget, uncheck "globalinclude".
or
2. Update pro file with "INCLUDEPATH += path where mywidget.h"
Please check for more info Promoting Widget

Using OSG's osgViewerQt example with Qt signals/slots

I have already posted this in the OSG mailing list, but the mailing list seems to be a bit slow.
Anyway, I'm trying to modify the osgViewerQt example by adding a new class of my
own that will contain the viewer. The design is:
wrapper.h: Defines class Wrapper. It inherits from
QMainWindow and has a
QDockWidget where the ViewerWidget will be attached.
viewer.h: Defines ViewerWidget class. It's the class from the
example, with a few mods by me.
prueba_qt.cpp: Main function and where a QApplication is created. A Wrapper object is
created here.
The project compiles, but when I execute it, I get an error:
QWidget: Must construct a QApplication before a QPaintDevice*
If I remove the Q_OBJECT line, the signal and the slot from
wrapper.h and compile the files from the terminal using
g++ -IE:/osg-3.0.1/install/include -LE:/osg-3.0.1/install/bin -IC:/Qt64/4.8/include -LC:/Qt64/4.8/bin -losgViewer -lOpenThreads -losgDB -losg -losgGA -losgQt -lQtCore4 -lQtGui4 prueba_qt.cpp
I can execute the app.
Can you please tell me what can I do to make this work? I've struggling all
morning but couldn't find the solution.
Thanks for your time!
PS: SO is Windows 7 64 bits # MingW compiler # Qt 4.8 # OSG 3.0.1
PS2: Here're the files I used in this project, including the pro file from qmake:
wrapper.h
#ifndef Wrapper_hpp
#define Wrapper_hpp
#include "viewer.h"
#include <QtGui/QMainWindow>
#include <QtGui/QDockWidget>
class Wrapper: public QMainWindow {
Q_OBJECT
private:
ViewerWidget* view;
QDockWidget* dock;
public:
Wrapper(void) {
view = new ViewerWidget();
dock = new QDockWidget;
dock->setWidget( view );
dock->setGeometry( 100, 100, 800, 600 );
dock->setAllowedAreas(Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, dock);
dock->show();
}
void Do(void) { view->Do(); }
void Add(void) { view->Add(); }
virtual ~Wrapper(void) {}
public slots:
void MySlot(void) {}
signals:
void MySignal(void);
};
#endif
wrapper.cpp
(This exists only because I read in the Qt forum that moc can only parse cpp files and thus one is needed for the signal/slot mechanism.)
#include "wrapper.h"
Wrapper::Wrapper(void) {
view = new ViewerWidget();
// view->setGeometry( 100, 100, 800, 600 );
dock = new QDockWidget;
dock->setWidget( view );
dock->setGeometry( 100, 100, 800, 600 );
dock->setAllowedAreas(Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, dock);
dock->show();
}
prueba_qt.cpp
#include <QtGui/QApplication>
#include <iostream>
#include "wrapper.h"
int main( int argc, char** argv ) {
osg::ArgumentParser arguments(&argc, argv);
QApplication app(argc, argv);
Wrapper wrap;
wrap.resize(800,600);
wrap.setWindowTitle("Cow");
wrap.showNormal();
wrap.Do();
return app.exec();
}
prueba_qt.pro
######################################################################
# Automatically generated by qmake (2.01a) mar 12. mar 13:45:28 2013
######################################################################
QT += core gui
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . E:/osg-3.0.1/install/include
LIBS += -LE:/osg-3.0.1/install/bin -losg -lOpenThreads -losgDB -losgGA -losgQt -losgViewer
# Input
HEADERS += viewer.h wrapper.h
SOURCES += prueba_qt.cpp wrapper.cpp
viewer.h: This is quite big, so I uploaded it to pastebin
EDIT #1
I have set OSG_NOTIFY_LEVEL to DEBUG_INFO and got this humongous output. The line with the error is:
FindFileInPath() : trying C:\cygwin\bin\osgPlugQWidget: Must construct a QApplication before a QPaintDevice
EDIT #2
The signal and slot were missing in the code. I have just added them to wrapper.h along with the call to Q_OBJECT.
After a little nap, I revised again the libraries used in the project. The problem was that some of those libraries were in debug mode and some in release mode. When using signals and slots, moc went crazy.
After building OSG debug libraries, I tried again my little example and worked.
So it's done!

Unresolved external symbols - Qt creator

I must be missing a basic concept with headers and includes because when I attempt to call even the simplest of a function from a separate source file I get an error:
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl
buildDeck(int,int)" (?buildDeck##YAXHH#Z) referenced in function _main
deck.h
#ifndef DECK_H
#define DECK_H
#include <QString>
void buildDeck(int deckSize, int jokers);
struct card
{
QString suit;
QString color;
int rank;
};
#endif // DECK_H
deck.cpp
#include"mainwindow.h"
#include "deck.h"
void buildDeck(int deckSize, int jokers)
{
int blackRed = deckSize-=jokers;
}
main.cpp
#include "mainwindow.h"
#include "deck.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
buildDeck(10,20);
return a.exec();
}
And this gives me an error. However, If I move the function definition from deck.cpp to the bottom of main.cpp, then the application will build.
All of the files are included in the same project, and stored in the same directory.
Other files:
.pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = carddeck
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
deck.cpp
HEADERS += mainwindow.h \
deck.h
FORMS += mainwindow.ui
not sure if you need it, but here's mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>
#include <QCheckBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void runButtonClicked();
private:
Ui::MainWindow *ui;
QPushButton *runButton;
QTextEdit * runText;
QCheckBox * betHearts;
QCheckBox * betDiamonds ;
QCheckBox * betClubs;
QCheckBox * betSpades ;
QCheckBox * betFlush ;
QCheckBox * betAllRed;
QCheckBox * betAllBlack ;
};
#endif // MAINWINDOW_H
It looks like the Makefile was not regenerated when you edited the .pro file.
Run qmake and try again.
You could also check if the deck.cpp is compiled or not; is there a deck.o in the build directory ?
yes, some time Makefile file is not updated while you change .pro file. So you have to run qmake.
Follow this steps:
Right click on project Clean / Build menu -> cleanAll
Right click on project Run qmake / Build menu -> runQmake
Right click on project Build / Build menu -> build
Pro Advice:
I don't know but sometime Qt is not updating Makefile. so i recomanded to all whenever you add/removing any resource in project or if any changes occur in your .pro file, just Run qmake and build your project(Running qmake do manually to update the path of project, which help to find the mainwindow.obj file).

Undefined reference to vtable... Q_OBJECT macro [duplicate]

This question already has answers here:
Qt Linker Error: "undefined reference to vtable" [duplicate]
(9 answers)
Closed 9 years ago.
When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am working on it.
myapp.h:
#ifndef MYAPP_H
#define MYAPP_H
#include <QApplication>
#include <QEvent>
#include <QObject>
#include <QDebug>
class MyApp : public QApplication
{
public:
MyApp( int argc, char** argv );
protected:
bool eventFilter(QObject *object, QEvent *event);
signals:
void focusG();
void focusL();
};
#endif // MYAPP_H
myapp.cpp:
#include "myapp.h"
MyApp::MyApp(int argc, char **argv): QApplication(argc, argv)
{
installEventFilter(this);
}
bool MyApp::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ApplicationDeactivate)
{
qDebug() << "Focus lost";
//focusL();
}
if (event->type() == QEvent::ApplicationActivate)
{
qDebug() << "Focus gained";
//focusG();
}
return false;
}
main.cpp:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QGraphicsObject>
#include <QTimer>
#include <QVariant>
#include "timecontrol.h"
#include "scorecontrol.h"
#include "Retry.h"
#include <QEvent>
#include "myapp.h"
int main(int argc, char *argv[])
{
//QApplication app(argc, argv);
MyApp app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.setMainQmlFile(QLatin1String("qml/Raker/main.qml"));
viewer.showExpanded();
QObject *rootObject = viewer.rootObject();
QTimer *timmer = new QTimer;
timmer->setInterval(1000);
TimeControl *timcon = new TimeControl;
scorecontrol *scorer = new scorecontrol;
Retry *probeer = new Retry;
QObject::connect(timmer, SIGNAL(timeout()), timcon, SLOT(updateTime()));
QObject::connect(timcon, SIGNAL(setTime(QVariant)), rootObject, SLOT(setTime(QVariant)));
QObject::connect(rootObject, SIGNAL(blockClicked(int, int)), scorer, SLOT(checkRight(int, int)));
QObject::connect(scorer, SIGNAL(setScore(QVariant)), rootObject, SLOT(setScore(QVariant)));
QObject::connect(scorer, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(rootObject, SIGNAL(start()), probeer, SLOT(Reetry()));
QObject::connect(probeer, SIGNAL(start()), timmer, SLOT(start()));
QObject::connect(probeer, SIGNAL(stop()), timmer, SLOT(stop()));
QObject::connect(probeer, SIGNAL(start(int)), scorer, SLOT(randomNum(int)));
QObject::connect(probeer, SIGNAL(sReset()), timcon, SLOT(reset()));
QObject::connect(probeer, SIGNAL(tReset()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(timeOut()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(timcon, SIGNAL(changeFinal()), scorer, SLOT(changeFinal()));
QObject::connect(scorer, SIGNAL(setFinal(QVariant)), rootObject, SLOT(setFinal(QVariant)));
QObject::connect(&app, SIGNAL(focusL()), probeer, SLOT(focusL()));
QObject::connect(&app, SIGNAL(focusG()), probeer, SLOT(focusG()));
return app.exec();
}
BlockToucher.pro:
# Add more folders to ship with the application, here
folder_01.source = qml/Raker
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
symbian:TARGET.UID3 = 0x2004b49f
# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
symbian:DEPLOYMENT.installer_header = 0x2002CCCF
# Allow network access on Symbian
symbian {
#TARGET.CAPABILITY += NetworkServices
vendorinfo = "%{\"Gerhard de Clercq\"}" ":\"Gerhard de Clercq\""
ICON = BlockToucher.svg
}
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
timecontrol.cpp \
scorecontrol.cpp \
Retry.cpp \
myapp.cpp \
myapplication.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()
HEADERS += \
timecontrol.h \
scorecontrol.h \
Retry.h \
myapp.h \
myapplication.h
OTHER_FILES += \
qtc_packaging/debian_fremantle/rules \
qtc_packaging/debian_fremantle/README \
qtc_packaging/debian_fremantle/copyright \
qtc_packaging/debian_fremantle/control \
qtc_packaging/debian_fremantle/compat \
qtc_packaging/debian_fremantle/changelog
compat \
qtc_packaging/debian_fremantle/changelog
Q_OBJECT is used by the MOC system to produce the code you need for the signals. My best guess would be that you are not included the MOC generated files in your project (the CPP files which it generates).
How you do this greatly depends on your build system (CMake, QMake, AUtomake, MSVC) but you should refer to the tutorial with QMake first.
That is, the undefined reference to vtable is the error I sometimes get when I forget to update my Cmake files and have a Q_OBJECT.
Also, your ctor for MyApp is wrong, the signature must be:
MyApp( int & argc, char** argv );
The & is important should you ever use command-line parameters.
I had same issue when i decided to add Q_OBJECT into my header file.
First try run qmake manually.
If not resolved, so delete build folder and build project again
If building all of the project is a heavy task, so try following steps:
Add a new temp class with QObject as its base class
Double check your header and source file for any mistake using new temp class
Build your project. It should built successfully
Remove your temp class completely (.h and .cpp file and relative lines on .pro file)
Good luck :)