2012-02-27 63 views
1

我提出了从文件夹中的“mainwindow.ui”文件中的一些变化没有表现出设计变更。 我已经添加了题为“文件”的新头衔,有只有两个简单的选项,“添加分形”和“退出”Qt Creator的:“形式”:运行时

enter image description here

你也可以看到,无论是在mainwindow.ui文件: enter image description here

但是当我运行该项目,窗口不显示如我所愿。标签没有显示。

enter image description here

我有新建,改建和制造,并且仍然有这个奇怪的事情。 任何人都可以帮我一把吗?

mainwindow.h

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 

namespace Ui { 
    class MainWindow; 
} 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 

private: 
    Ui::MainWindow *ui; 
    void createActions(); 
    void createMenus(); 
    // Widgets i layouts 
    QWidget *centralWidget; 
    // Accions associades als menus 
    QAction *exitAct; 
    // Menus principals 
    QMenu *fileMenu; 
}; 

#endif // MAINWINDOW_H 

mainwindow.cpp

#include "mainwindow.h" 
#include "ui_mainwindow.h" 

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 
    centralWidget = new QWidget; 
    setCentralWidget(centralWidget); createActions(); 
    createMenus(); 
    setWindowTitle(tr("Practica 1: GiVD 2011-2012")); 
    resize(640, 480); 
} 

void MainWindow::createActions() { 
    exitAct = new QAction(tr("&Exit"), this); 
    exitAct->setShortcut(tr("Ctrl+Q")); 
    exitAct->setStatusTip(tr("Sortir del programa")); 
    connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); 
} 

void MainWindow::createMenus() 
{ 
    fileMenu = menuBar()->addMenu(tr("&File")); 
    fileMenu->addSeparator(); 
    // Per a cada nou submenú has de fer un addAction 
    fileMenu->addAction(exitAct); 
} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 

的main.cpp

#include <QtGui/QApplication> 
#include "mainwindow.h" 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 
    MainWindow w; 
    w.show(); 

    return a.exec(); 
} 

mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?> 
<ui version="4.0"> 
<class>MainWindow</class> 
<widget class="QMainWindow" name="MainWindow"> 
    <property name="geometry"> 
    <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>400</width> 
    <height>300</height> 
    </rect> 
    </property> 
    <property name="windowTitle"> 
    <string>MainWindow</string> 
    </property> 
    <widget class="QWidget" name="centralWidget"/> 
    <widget class="QMenuBar" name="menuBar"> 
    <property name="geometry"> 
    <rect> 
    <x>0</x> 
    <y>0</y> 
    <width>400</width> 
    <height>22</height> 
    </rect> 
    </property> 
    <widget class="QMenu" name="menuFile"> 
    <property name="title"> 
    <string>File</string> 
    </property> 
    <addaction name="actionAdd_Fractal"/> 
    <addaction name="actionExit"/> 
    </widget> 
    <addaction name="menuFile"/> 
    </widget> 
    <widget class="QToolBar" name="mainToolBar"> 
    <attribute name="toolBarArea"> 
    <enum>TopToolBarArea</enum> 
    </attribute> 
    <attribute name="toolBarBreak"> 
    <bool>false</bool> 
    </attribute> 
    </widget> 
    <widget class="QStatusBar" name="statusBar"/> 
    <action name="actionAdd_Fractal"> 
    <property name="text"> 
    <string>Add Fractal</string> 
    </property> 
    </action> 
    <action name="actionExit"> 
    <property name="text"> 
    <string>Exit</string> 
    </property> 
    </action> 
</widget> 
<layoutdefault spacing="6" margin="11"/> 
<resources/> 
<connections/> 
</ui> 
+0

我个人不使用Qt Creator,但你确定UIC运行在你的.ui文件上吗?并且生成的头文件更新了吗? – Bart 2012-02-27 15:45:47

+0

我怎么知道?对不起巴特,但我现在与Qt Creator和C++。至少,在.pro文件我有“形成+ = mainwindow.ui ” – user963658 2012-02-27 15:47:30

+0

从我的理解(但其他人可能指正)添加的.ui到形式都应当确保UIC被调用。这应该生成一个具有类似名称的.h文件,其中包含用于设置GUI的C++代码。看看这样的文件是否确实生成并且是您项目的一部分。 – Bart 2012-02-27 15:50:25

回答

2

我钻进了同样的问题,直到我意识到,菜单的在Mac OS出现在顶部,而不是在应用程序窗口。

看看这是你的情况。

谢谢,