PDA

View Full Version : Using UI class from Designer?



miivers
21st September 2010, 10:58
Hello
I have finished a qt tutorial from another site. Everything runs fine except the GUI i made in QT Designer does not show up. All tutorials I can find on the subject implements it the same way.

So to summon it up. I only get a blank window when I run my project.

Main.cpp


#include <QtCore/QCoreApplication>
#include "TempForm.h"
#include "Window.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

Window mWindow;
mWindow.resize(800,600);
mWindow.show();

return a.exec();
}
#endif


Window.h


#ifndef WINDOW_H
#define WINDOW_H

#include <QtOpenGl/QGLWidget>
#include <QtGui>
#include "TempForm.h"

class Window : public QWidget , private Ui::MainWindow //MainWindow is the class name from QT Designer header file (TempForm.h)
{
public:
Window(QWidget *parent = 0);
~Window();
};
#endif


Window.cpp


#include <QtGui/QMouseEvent>
#include "Window.h"

Window::Window(QWidget *parent)
{
setupUi(&(QMainWindow)this); // this sets up GUI
}
Window::~Window()
{

}


If I manually call each guielemts show function my application crash.

Any suggestions?

Zlatomir
21st September 2010, 11:04
Try this:


#include <QtGui/QMouseEvent>
#include "Window.h"

Window::Window(QWidget *parent)
{
setupUi(this); // this sets up GUI
}



LE: And you include TempForm.h and private inherit from Ui::MainWindow? something is not right in there (you should public inherit the class that UIC created for you)

Here (http://doc.trolltech.com/4.6/designer-using-a-ui-file.html) is the official guide that is presenting you all you need to know on how to integrate ui file in your c++ code.

miivers
21st September 2010, 12:15
Thanks for looking over it.

Yeah private inherit was not intended but dident solw the problem either.

Using this was giving an error witch is not strange. Thats why I was casting.


setupUi(this); // this sets up GUI


By inherit from QMainWindow rather than QWidget fixed the problem for me.

wysota
21st September 2010, 16:21
I have finished a qt tutorial from another site. Everything runs fine except the GUI i made in QT Designer does not show up. All tutorials I can find on the subject implements it the same way.
Maybe you shouldn't take tutorials from those "other sites" ;)