【发布时间】:2017-04-13 13:26:52
【问题描述】:
我是 Qt 的新手。我正在尝试从 myMyMainWindow 打开花药 window 。我无法理解,我在这种情况下做错了什么。不想让你们解决我的问题,只是说请,我做错了什么。
所以我有一个MainWindow.h(看看这个评论,认为你不需要了解它的整个过程):
#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H
#include <QDialog>
#include <QMainWindow>
#include <QPushButton>
#include <QLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "timer.h"
class MyMainWindow: public QMainWindow
{
Q_OBJECT
private:
QPushButton *timer_Button;
QPushButton *StopWatch;
QPushButton *Close;
T_timer *myTimer;
public:
MyMainWindow(QWidget *parent);
public slots:
void Open_Timer_Window(); // Slot for opening a new window
};
#endif // MYMAINWINDOW_H
我的MyMainWindow.cpp 文件:
#include "MyMainWindow.h"
MyMainWindow::MyMainWindow(QWidget *parent=0): QDialog(parent)
{
// just creating Buttons
timer_Button = new QPushButton ("Timer");
Close=new QPushButton("Close");
QHBoxLayout *Up=new QHBoxLayout;
Up->addWidget(timer_Button);
QHBoxLayout *Down=new QHBoxLayout;
Down->addWidget(Close);
QVBoxLayout *Main=new QVBoxLayout;
Main->addLayout(Up);
Main->addLayout(Down);
// the main part
connect(Close,SIGNAL(clicked()),this,SLOT(close()));
connect(timer_Button,SIGNAL(clicked()),this,SLOT(Open_Timer_Window()));// call `Slot of Open_Timer_Window()`
setLayout(Main);
setWindowTitle("Smart Watch");
}
void MyMainWindow::Open_Timer_Window()
{
myTimer = new T_timer(0);
myTimer->show();
}
所以,我想我应该给你看第二个窗口,可能有错误:
The header:
#include <QPushButton>
#include <QDialog>
#include <QHBoxLayout>
#include <QVBoxLayout>
class T_timer : public QDialog
{
Q_OBJECT
private:
QPushButton Start;
QPushButton Stop;
public:
T_timer(QWidget *parent=0);
};
还有.cpp:
#include "timer.h"
T_timer::T_timer(QWidget *parent=0): QDialog(parent)
{
Start=new QPushButton ("Start");
Stop=new QPushButton ("Stop");
QHBoxLayout *Up=new QHBoxLayout;
Up->addWidget(Start);
Up->addWidget(Stop);
setLayout(Up);
}
总的来说,我的 MainWindow 出现在屏幕上,单击按钮 timer 后,我没有任何操作。请帮助我,如果可以的话。谢谢。
【问题讨论】: