I found a tutorial about creating widgets and layouts without using the Qt designer:
http://www.bogotobogo.com/Qt/Qt5_Lay...ngDesigner.php
What I'm stuck on is how to connect the buttons to slots.
The following code compiles, but it gets all sorts of linking errors.I've commented out the code that causes the linking errors.
Any help getting this to work would be appreciated.
.pro file is:
QT += widgets
SOURCES += \
main.cpp
QT += widgets
SOURCES += \
main.cpp
To copy to clipboard, switch view to plain text mode
Source is:
#include <QApplication>
#include <QPushButton>
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QObject>
//class ButtonWatcher : public QObject{
// Q_OBJECT
//public:
// ButtonWatcher(QObject *parent = 0);
//public slots:
// void buttonPressed();
//};
//ButtonWatcher::ButtonWatcher(QObject *parent) : QObject(parent){
//}
//void ButtonWatcher::buttonPressed(){
// qDebug()<<"Button clicked";
//}
int main(int argc, char* argv[])
{
// ButtonWatcher *button = new ButtonWatcher();
// QObject::connect(b,SIGNAL(clicked(bool)),button,SLOT(buttonPressed()));
b->show();
return app.exec();
}
#include <QApplication>
#include <QPushButton>
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QObject>
//class ButtonWatcher : public QObject{
// Q_OBJECT
//public:
// ButtonWatcher(QObject *parent = 0);
//public slots:
// void buttonPressed();
//};
//ButtonWatcher::ButtonWatcher(QObject *parent) : QObject(parent){
//}
//void ButtonWatcher::buttonPressed(){
// qDebug()<<"Button clicked";
//}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton *b = new QPushButton("Click me");
// ButtonWatcher *button = new ButtonWatcher();
// QObject::connect(b,SIGNAL(clicked(bool)),button,SLOT(buttonPressed()));
b->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Here are the linking errors:
main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl ButtonWatcher::metaObject(void)const " (?metaObject@ButtonWatcher@@UEBAPEBUQMetaObject@@X Z)
main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __cdecl ButtonWatcher::qt_metacast(char const *)" (?qt_metacast@ButtonWatcher@@UEAAPEAXPEBD@Z)
main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __cdecl ButtonWatcher::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@ButtonWatcher@@UEAAHW4Call@QMetaObje ct@@HPEAPEAX@Z)
debug\WithoutDesigner.exe:-1: error: LNK1120: 3 unresolved externals
Bookmarks