本学期的OOP大程决定用Qt来写,今天开始了对它的学习~
我开始是决定通过实战来边做边学,想做一个简单的界面:有一个button和一个spinbox,button每按一下,spinbox里的值都会+1。
结果这么简单的一个小功能做了2个多小时。。。是因为我对Qt的消息槽的机制还不是很理解,本以为直接将clicked与setValue连接起来就可以了,结果当然是编译失败。然后我就自己写了一个slot函数,如下:
#ifndef MYSPINBOX_H
#define MYSPINBOX_H
#include
#include
class MySpinBox:public QSpinBox
{
Q_OBJECT
private:
int value;
public:
MySpinBox(QWidget *parent=0);
void changeValue();
};
#endif // MYSPINBOX_H
#include "myspinbox.h"
MySpinBox::MySpinBox(QWidget *parent):QSpinBox(parent)
{
this->value = 0;
}
void MySpinBox::changeValu