我在模态视图中使用QT在表单之间发送两个整数时遇到问题。 我希望第一个表单将两个整数发送到第二个表单(当我单击一个按钮时)。 应该发送整数的函数(shut_down_timer.cpp):
void shut_down_timer::on_setShutDown_clicked()
{
close();
timer t;
t.setHours(5);
t.setMinutes(6);
t.setModal(true);
t.exec();
}
第二种形式的标题(timer.h):
class timer;
}
class timer : public QDialog
{
Q_OBJECT
public:
void setHours(int h);
void setMinutes(int m);
explicit timer(QWidget *parent = 0);
~timer();
private slots:
void on_CloseButton_clicked();
private:
Ui::timer *ui;
int hours;
int minutes;
};
存储int的函数(timer.cpp):
void timer::setHours(int h){
hours=h;
}
void timer::setMinutes(int m){
minutes=m;
}
你能发现问题吗? 提前谢谢!
完整代码: 首先来自标题(shut_down_timer.h):
#ifndef SHUT_DOWN_TIMER_H
#define SHUT_DOWN_TIMER_H
#include <QDialog>
#include "timer.h"
namespace Ui {
class shut_down_timer;
}
class shut_down_timer : public QDialog
{
Q_OBJECT
public:
explicit shut_down_timer(QWidget *parent = 0);
~shut_down_timer();
private slots:
void on_setShutDown_clicked();
private:
Ui::shut_down_timer *ui;
timer *t;
};
#endif // SHUT_DOWN_TIMER_H
首先形成cpp(shut_down_timer.cpp):
#include "shut_down_timer.h"
#include "ui_shut_down_timer.h"
shut_down_timer::shut_down_timer(QWidget *parent) :
QDialog(parent),
ui(new Ui::shut_down_timer)
{
ui->setupUi(this);
}
shut_down_timer::~shut_down_timer()
{
delete ui;
}
void shut_down_timer::on_setShutDown_clicked()
{
close();
timer t;
t.setHours(ui->timeEdit->time().hour());
t.setMinutes(ui->timeEdit->time().second());
t.setModal(true);
t.exec();
}
第二个表头(timer.h):
#ifndef TIMER_H
#define TIMER_H
#include <QDialog>
namespace Ui {
class timer;
}
class timer : public QDialog
{
Q_OBJECT
public:
void setHours(int h);
void setMinutes(int m);
explicit timer(QWidget *parent = 0);
~timer();
private slots:
void on_CloseButton_clicked();
private:
Ui::timer *ui;
int hours;
int minutes;
};
#endif // TIMER_H
第二种形式cpp(timer.cpp):
#include "timer.h"
#include "ui_timer.h"
#include "LCDNumber.h"
#include <QFrame>
#include <QLayout>
#include <QString>
timer::timer(QWidget *parent) :
QDialog(parent),
ui(new Ui::timer)
{
ui->setupUi(this);
QWidget *centralWidget = new QWidget(this);
LCDNumber *number = new LCDNumber(centralWidget,1,30,0);
number->setFrameShape(QFrame::NoFrame);
number->setGeometry(10,10,261,61);
number->timer->start(1000);
}
timer::~timer()
{
delete ui;
}
void timer::setHours(int h){
hours=h;
}
void timer::setMinutes(int m){
minutes=m;
}
void timer::on_CloseButton_clicked()
{
close();
}