sig.h
#ifndef SIG_H
#define SIG_H
#include <QtGui/QDialog>
#include <QLabel>
#include <QPushButton>
class sig : public QDialog
{
Q_OBJECT
public:
sig(QWidget *parent = 0, Qt::WFlags flags = 0);
~sig();
public slots:
void showTimes(void);
public:signals:
void mySig(QString str);
private:
QLabel *showTime;
QPushButton* getTimeBtn;
};
#endif // SIG_H
sig.cpp
#include <QTime>
#include "sig.h"
sig::sig(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
this->resize(400, 500);
showTime = new QLabel(this);
getTimeBtn = new QPushButton(this);
showTime->resize(200,50);
showTime->move(150, 50);
getTimeBtn->move(150,400);
connect(getTimeBtn, SIGNAL(clicked()), this, SLOT(showTimes()));
connect(this,SIGNAL(mySig(QString)), showTime, SLOT(setText(QString)));
}
sig::~sig()
{
}
void sig::showTimes(void)
{
QString str = QTime::currentTime().toString("hh:mm:ss");
emit mySig(str);
}
main.cpp
#include "sig.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
sig w;
w.show();
return a.exec();
}