Skip to content

Instantly share code, notes, and snippets.

@pedrovanzella
Created January 9, 2019 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrovanzella/c6f5ce7a080f6fc4b5f423d6974dfa86 to your computer and use it in GitHub Desktop.
Save pedrovanzella/c6f5ce7a080f6fc4b5f423d6974dfa86 to your computer and use it in GitHub Desktop.
Q_OBJECT weirdness
#include <QApplication>
#include "window.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
Undefined symbols for architecture x86_64:
"vtable for Window", referenced from:
Window::Window(QWidget*) in window.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)
TEMPLATE = app
TARGET = tutorial
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
main.cpp \
window.cpp
HEADERS += \
window.h
#include "window.h"
#include <QPushButton>
#include <QApplication>
#include <QProgressBar>
#include <QSlider>
Window::Window(QWidget *parent) : QWidget(parent)
{
setFixedSize(800, 600);
m_button = new QPushButton("Hello, World", this);
m_button->setGeometry(10, 10, 160, 30);
m_button->setCheckable(true);
connect(m_button, &QPushButton::clicked, this, &Window::slotButtonClicked);
m_slider = new QSlider(this);
m_slider->setOrientation(Qt::Horizontal);
m_slider->setRange(0, 100);
m_slider->setValue(0);
m_slider->setGeometry(10, 30, 180, 30);
m_progress_bar = new QProgressBar(this);
m_progress_bar->setRange(0, 100);
m_progress_bar->setValue(0);
m_progress_bar->setGeometry(10, 50, 180, 30);
connect(m_slider, &QSlider::valueChanged, m_progress_bar, &QProgressBar::setValue);
}
void Window::slotButtonClicked(bool checked)
{
if (checked) {
m_button->setText("Checked");
} else {
m_button->setText("Hello, World");
}
}
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
class QPushButton;
class QProgressBar;
class QSlider;
class Window : public QWidget
{
//Q_OBJECT
public:
explicit Window(QWidget *parent = nullptr);
private slots:
void slotButtonClicked(bool checked);
private:
QPushButton *m_button;
QProgressBar *m_progress_bar;
QSlider *m_slider;
};
#endif // WINDOW_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment