Created
January 9, 2019 00:35
-
-
Save pedrovanzella/c6f5ce7a080f6fc4b5f423d6974dfa86 to your computer and use it in GitHub Desktop.
Q_OBJECT weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include "window.h" | |
int main(int argc, char **argv) | |
{ | |
QApplication app(argc, argv); | |
Window window; | |
window.show(); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEMPLATE = app | |
TARGET = tutorial | |
QT = core gui | |
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
SOURCES += \ | |
main.cpp \ | |
window.cpp | |
HEADERS += \ | |
window.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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