I am on MacOS and I want to inherit QWidget for a class with QObject:: connect but i have a error:
Undefined symbols for architecture x86_64: "vtable for Core", referenced from: Core::Core(QWidget*) in Core.cpp.o NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [bin/babel] Error 1 make[1]: *** [CMakeFiles/babel.dir/all] Error 2
Core.cpp
** EPITECH PROJECT, 2020
** Babel
** File description:
** Core
*/
#include "../include/Core.hpp"
Core::Core(QWidget *parent) : QWidget(parent)
{
this->text = new QLabel("Pseudo", this);
this->textArea = new QTextEdit(this);
this->button = new QPushButton("Connexion", this);
QObject::connect(this->button, SIGNAL(clicked()), this, SLOT(this->buttonPushed()));
this->button->setGeometry(300, 250, 160, 30);
this->textArea->setGeometry(300, 200, 160, 30);
this->text->setGeometry(335, 175, 160, 30);
}
Core::~Core()
{
}
void Core::buttonPushed()
{
printf("EKIP EKIP EKIP\n");
}
Core.hpp:
/*
** EPITECH PROJECT, 2020
** Babel
** File description:
** Core
*/
#ifndef CORE_HPP_
#define CORE_HPP_
#include <stdio.h>
#include <stdlib.h>
#include <opus/opus.h>
#include <portaudio.h>
#include <QtWidgets>
class Core : public QWidget {
Q_OBJECT
public:
explicit Core(QWidget *parent = nullptr);
~Core();
protected:
private slots:
void buttonPushed();
private:
// QApplication *app;
QPushButton *button;
QLabel *text;
QTextEdit *textArea;
};
#endif /* !CORE_HPP_ */
and Main.cpp
/*
** EPITECH PROJECT, 2020
** Babel
** File description:
** main
*/
#include "../include/Core.hpp"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Core *core = new Core();
core->setGeometry(10, 10, 720, 480);
core->setWindowTitle("Babel");
core->show();
return app.exec();
}
Cmake file:
project(Babel)
cmake_minimum_required(VERSION 2.8.12)
add_definitions("-fPIC")
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTOUIC ON)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core)
find_package(Qt5Network)
file(GLOB_RECURSE BABEL_SRC PATH ./sources/*.cpp)
include_directories(${CMAKE_INCLUDE_PATH})
add_executable(babel ${BABEL_SRC})
target_link_libraries(babel ${CONAN_LIBS} Qt5::Widgets Qt5::Core Qt5::Network)
add the files with Q_OBJECT in the cmake like this for example:
set(SOURCES core.cpp )
qt5_wrap_cpp(SOURCES core.hpp)
add_executable(babel ${SOURCES} ${BABEL_SRC})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.