• 5149阅读
  • 3回复

麻烦大家帮我看一下哪里不对,为什么运行的时候主菜单什么都没显示,空白的 [复制链接]

上一主题 下一主题
离线iversonkimi
 

只看楼主 正序阅读 楼主  发表于: 2010-05-26
头文件:


#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;

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow();



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

----------------------------------------------------------------------------------------------

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);
}









离线iversonkimi

只看该作者 3楼 发表于: 2010-05-27
回 1楼(mysi) 的帖子
你好 ,我那个界面是用代码写的,没有用designer ,也要这句话吗?谢谢
离线wd007

只看该作者 2楼 发表于: 2010-05-26
代码太长了,你调试过了吗?
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线mysi
只看该作者 1楼 发表于: 2010-05-26
一般默认生成的QMainwindow都有一句话的ui.setUP(this),你看看你的是否少了
快速回复
限100 字节
 
上一个 下一个