I am new in Qt. And I am trying to open anther window
from myMyMainWindow
. I can't catch, what I am doing wrong with this situation. Don't want you guys to solve my problem, just say to please, what I am doing wrong.
So I have got a MainWindow.h
( look at this comment, think you don't need to understand the whole proccess of it):
#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
My MyMainWindow.cpp
file:
#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();
}
So, I think I should show you the Second window, might be there is a mistake:
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);
};
And .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);
}
Totally, I have got my MainWindow on the screen and after click a button timer
, I haven't got an action.Help me please, if you can. Thanks.