当前位置: 技术问答>linux和unix
QT编程的问题?(十万火急)
来源: 互联网 发布时间:2015-03-24
本文导语: 代码如下, //lcdrange.cpp文件如下 #include "lcdrange.h" #include #include LCDRange::LCDRange( QWidget *parent, const char *name ) : QVBox( parent, name ) { QLCDNumber *lcd = new QLCDNumber( 2, this, "lcd" ); sli...
代码如下,
//lcdrange.cpp文件如下
#include "lcdrange.h"
#include
#include
LCDRange::LCDRange( QWidget *parent, const char *name )
: QVBox( parent, name )
{
QLCDNumber *lcd = new QLCDNumber( 2, this, "lcd" );
slider = new QSlider( Horizontal, this, "slider" );
slider->setRange( 0, 99 );
slider->setValue( 0 );
connect( slider, SIGNAL(valueChanged(int)),
lcd, SLOT(display(int)) );
connect( slider, SIGNAL(valueChanged(int)),
SIGNAL(valueChanged(int)) );
}
int LCDRange::value() const
{
return slider->value();
}
void LCDRange::setValue( int value )
{
slider->setValue( value );
}
//lcdrange.h文件如下
#ifndef LCDRANGE_H
#define LCDRANGE_H
#include
#include
class QSlider;
class LCDRange : public QVBox
{
Q_OBJECT
public:
LCDRange( QWidget *parent=0, const char *name=0 );
int value() const;
public slots:
void setValue( int );
signals:
void valueChanged( int );
private:
QSlider *slider;
};
#endif
//main.cpp文件如下
#include
#include
#include
#include
#include
#include
#include "lcdrange.h"
class MyWidget : public QVBox
{
public:
MyWidget( QWidget *parent=0, const char *name=0 );
};
MyWidget::MyWidget( QWidget *parent, const char *name )
: QVBox( parent, name )
{
QPushButton *quit = new QPushButton( "Quit", this, "quit" );
quit->setFont( QFont( "Times", 18, QFont::Bold ) );
connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
QGrid *grid = new QGrid( 4, this );
LCDRange *previous = 0;
for( int r = 0 ; r
//lcdrange.cpp文件如下
#include "lcdrange.h"
#include
#include
LCDRange::LCDRange( QWidget *parent, const char *name )
: QVBox( parent, name )
{
QLCDNumber *lcd = new QLCDNumber( 2, this, "lcd" );
slider = new QSlider( Horizontal, this, "slider" );
slider->setRange( 0, 99 );
slider->setValue( 0 );
connect( slider, SIGNAL(valueChanged(int)),
lcd, SLOT(display(int)) );
connect( slider, SIGNAL(valueChanged(int)),
SIGNAL(valueChanged(int)) );
}
int LCDRange::value() const
{
return slider->value();
}
void LCDRange::setValue( int value )
{
slider->setValue( value );
}
//lcdrange.h文件如下
#ifndef LCDRANGE_H
#define LCDRANGE_H
#include
#include
class QSlider;
class LCDRange : public QVBox
{
Q_OBJECT
public:
LCDRange( QWidget *parent=0, const char *name=0 );
int value() const;
public slots:
void setValue( int );
signals:
void valueChanged( int );
private:
QSlider *slider;
};
#endif
//main.cpp文件如下
#include
#include
#include
#include
#include
#include
#include "lcdrange.h"
class MyWidget : public QVBox
{
public:
MyWidget( QWidget *parent=0, const char *name=0 );
};
MyWidget::MyWidget( QWidget *parent, const char *name )
: QVBox( parent, name )
{
QPushButton *quit = new QPushButton( "Quit", this, "quit" );
quit->setFont( QFont( "Times", 18, QFont::Bold ) );
connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
QGrid *grid = new QGrid( 4, this );
LCDRange *previous = 0;
for( int r = 0 ; r