• 5680阅读
  • 2回复

又来求教了 程序运行一片空白 [复制链接]

上一主题 下一主题
离线iversonkimi
 

只看楼主 倒序阅读 楼主  发表于: 2010-05-27
大家好,我想请问一下几个不同布局的页面可以切换要怎么实现? 为什么我的代码通过编译后运行的时候是一片空白,是不是除了main函数中要.show以外,在其他页面的cpp文件中也要加入各个部件的show的语句??

还有,析构函数是不是必须的?

另外想问下,我没用Qt designer,但是在所有文件中还是看到了ui_mainwindow.h,这个文件里的代码根本和我的页面不符合,是要删除还是什么,是不是因为这个原因才使我的程序一片空白?

几个子页面还没写,只是简单的弄了一下

谢谢大家

-----------------------------------------------------------------------------------------------mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class QLabel;
class QToolButton;
class QDateTime;
class Match;
class Check;
class Setting;
class Data;
class QGridLayout;
class QHBoxLayout;
class QVBoxLayout;


class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget *parent = 0);




private slots:
    void goMatch();
    void goCheck();
    void goSetting();
    void goData();


private:
    void createToolButton();
    void createLabel();
    void createDateTime();
    void createLayout();

    QLabel *timeLabel;
    QDateTime *dateTime;
    QToolButton *matchButton;
    QToolButton *checkButton;
    QToolButton *settingButton;
    QToolButton *dataButton;
    QToolButton *closeButton;
    QLabel *matchLabel;
    QLabel *checkLabel;
    QLabel *settingLabel;
    QLabel *dataLabel;
    QLabel *closeLabel;

};



#endif // MAINWINDOW_H


------------------------------------------------------------------mainwindow.cpp



#include <QtGui>

#include "check.h"
#include "match.h"
#include "mainwindow.h"
#include "setting.h"
#include "data.h"

MainWindow::MainWindow()
{
    createToolButton();
    createLabel();
    createLayout();

}

void MainWindow::createToolButton()
{
    matchButton = new QToolButton;
    matchButton->setIcon(QIcon(":/images/match.png"));
    connect(matchButton, SIGNAL(clicked()), this, SLOT(goMatch()));

    checkButton = new QToolButton;
    checkButton->setIcon(QIcon(":/images/check.png"));
    connect(checkButton, SIGNAL(clicked()), this, SLOT(goCheck()));

    settingButton = new QToolButton;
    settingButton->setIcon(QIcon(":/images/setting.png"));
    connect(settingButton, SIGNAL(clicked()), this, SLOT(goSetting()));

    dataButton = new QToolButton;
    dataButton->setIcon(QIcon(":/images/data.png"));
    connect(dataButton, SIGNAL(clicked()), this, SLOT(goData()));

    closeButton = new QToolButton;
    closeButton->setIcon(QIcon(":/images/close.png"));
}

void MainWindow::createLabel()
{
    matchLabel = new QLabel;
    matchLabel->setText("Match");

    checkLabel = new QLabel;
    checkLabel->setText("Check");

    settingLabel = new QLabel;
    settingLabel->setText("Setting");

    dataLabel = new QLabel;
    dataLabel->setText("Data");

    closeLabel = new QLabel;
    closeLabel->setText("Close");
}

void MainWindow::createLayout()
{
    QGridLayout *lowerLayout = new QGridLayout;
    lowerLayout->addWidget(matchButton,2,0,5,1);
    lowerLayout->addWidget(checkButton,2,1,5,1);
    lowerLayout->addWidget(dataButton,2,2);
    lowerLayout->addWidget(settingButton,4,2);
    lowerLayout->addWidget(closeButton,6,2);
    lowerLayout->addWidget(matchLabel,7,0);
    lowerLayout->addWidget(checkLabel,7,1);
    lowerLayout->addWidget(dataLabel,3,2);
    lowerLayout->addWidget(settingLabel,5,2);
    lowerLayout->addWidget(closeLabel,7,2);

    QHBoxLayout *upperLayout = new QHBoxLayout;
    upperLayout->addWidget(timeLabel);
    upperLayout->addStretch();

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(upperLayout);
    mainLayout->addLayout(lowerLayout);


    setLayout(mainLayout);
    setWindowTitle(tr("colourmeter"));
}



void MainWindow::goMatch()
{
    Match mainwindow(this);
}

void MainWindow::goCheck()
{
   Check mainwindow(this);
}

void MainWindow::goSetting()
{
    Setting mainwindow(this);
}

void MainWindow::goData()
{
    Data mainwindow(this);
}


-----------------------------------------------------------子页面match.h  (另外几个子页面和他相同的现在)


#ifndef MATCH_H
#define MATCH_H



#include <QMainWindow>

class Match : public QMainWindow {
    Q_OBJECT
public:
    Match(QWidget *parent = 0);
};
#endif // MATCH_H


--------------------------------------------------------match.cpp

#include <QtGui>

#include "match.h"


Match::Match(QWidget *parent)
{


}







[ 此帖被iversonkimi在2010-05-27 12:28重新编辑 ]
离线mysi
只看该作者 1楼 发表于: 2010-05-27
看一下qt第四版,是手把手教你怎么写的。
离线wd007

只看该作者 2楼 发表于: 2010-05-27
你打断点调试一下,看看。

这么长的代码,大家不好看的。
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
快速回复
限100 字节
 
上一个 下一个