Hey, my code compiles fine but I cannot connect my own functions to a signal. Is the reason because i have not put the Q_OBJECT macro in the class header file for the window?
if so when i do put this macro in i get 2 errors.
make: *** [debug] Error 2
make[1]: *** [debug\buttonTest.exe] Error 1
I was hoping if i fixed this then i would be able to connect signals to my own functions.
-----------------
{
Q_OBJECT
public:
{
slider
= new QSlider(Qt
::Horizontal);
slider->setRange(0,99);
slider->setValue(0);
QObject::connect(slider,
SIGNAL(valueChanged
(int)),
this, SLOT(Update(int)));
//lcd, SLOT(display(int)));
layout->addWidget(slider);
layout->addWidget(lcd);
layout->addWidget(button);
this->setLayout(layout);
}
private slots:
void Update(int i)
{
lcd->display(i);
}
private:
};
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = 0)
{
button = new QPushButton("Increment", this);
lcd = new QLCDNumber(2, this);
slider = new QSlider(Qt::Horizontal);
slider->setRange(0,99);
slider->setValue(0);
QObject::connect(slider, SIGNAL(valueChanged(int)),
this, SLOT(Update(int)));
//lcd, SLOT(display(int)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(slider);
layout->addWidget(lcd);
layout->addWidget(button);
this->setLayout(layout);
}
private slots:
void Update(int i)
{
lcd->display(i);
}
private:
QPushButton *button;
QLCDNumber *lcd;
QSlider *slider;
};
To copy to clipboard, switch view to plain text mode
//.pro file
TEMPLATE = app
TARGET = buttonTest
QT += core \
gui
HEADERS += buttontest.h
SOURCES += main.cpp \
buttontest.cpp
FORMS += buttontest.ui
RESOURCES +=
//.pro file
TEMPLATE = app
TARGET = buttonTest
QT += core \
gui
HEADERS += buttontest.h
SOURCES += main.cpp \
buttontest.cpp
FORMS += buttontest.ui
RESOURCES +=
To copy to clipboard, switch view to plain text mode
Bookmarks