1

I had made some changes on the 'mainwindow.ui' file from the folder: 'Forms'. I've added a new title entitled 'File' and there only two simple options, 'Add Fractal' and 'Exit'

enter image description here

You can also see that both are on the mainwindow.ui file:enter image description here

But when I run the project, the window is not showing as I wish. Tabs are not showing.

enter image description here

I had build, rebuild and make, and still have this strange thing. Can anyone give me a hand?

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>
user963658
  • 151
  • 1
  • 2
  • 9
  • I personally don't use Qt Creator, but are you sure that UIC gets run on your .ui file? And does the generated header file update? – Bart Feb 27 '12 at 15:45
  • How can I know that? Im sorry Bart but I'm now with the Qt Creator and C++. At least, on the .pro file I have 'FORMS += mainwindow.ui ' – user963658 Feb 27 '12 at 15:47
  • From what I understand (but someone else might correct me) adding the .ui to FORMS should ensure that UIC is being called. This should generate a .h file with a similar name, containing the C++ code to set up your GUI. Have a look if such a file is indeed generated and is part of your project. – Bart Feb 27 '12 at 15:50
  • 1
    Show to us the MainWindow class definition (in .h file) and the MainWindow constructor (in .cpp file). – borges Feb 27 '12 at 16:11
  • On the 'build' folder appears that new .h with the name 'ui_mainwindow.h' . I can read the tabs on the code, but they are not showing. I've delete it so it can re-make again, but still doesnt work. – user963658 Feb 27 '12 at 16:11
  • @borges - the message is now edited and you can see the Mainwindow.h and the mainwindow.cpp. – user963658 Feb 27 '12 at 16:14
  • MainWindow::createActions() and MainWindow::createMenus() shouldn't be necessary if you using an ui-file which creates the same actions/menus. – sgibb Feb 27 '12 at 16:31
  • It's not necessary but it should work with it.. – user963658 Feb 27 '12 at 16:33
  • Could you post your main.cpp and your mainwindow.ui too? – sgibb Feb 27 '12 at 16:45
  • @user963658 works like expected (linux, qt4.6, 2 menu entries "File" and so on). – sgibb Feb 27 '12 at 16:58
  • I'm using OSX, maybe that's the problem? Is there anything I have to do to run this in OSX? – user963658 Feb 27 '12 at 17:01
  • I'm betting that you need to use the "run qmake" option too. QtCreator really should do that automatically when it changes the .pro file (like when adding a new file), but it doesn't seem to always do that and thus the Make dependencies don't get updated. – Wes Hardaker Feb 27 '12 at 17:05
  • 1
    Stupid question: Did you check, that your menu does not appear in menu bar on the top of the screen? – Lol4t0 Feb 27 '12 at 19:35
  • Nevermind, works perfect on Linux so gonna leave OSX and start working on Linux for Qt Creator. Thanks to all the people who tried to give me a hand! – user963658 Feb 27 '12 at 20:14

1 Answers1

1

I got into the same issue until I realized that menu's on a mac OS appear at the top and not at the application window.

See if this is the case for you.

Thanks,