PDA

View Full Version : Qt 3 program & Qt4 designer



impeteperry
29th January 2006, 19:09
I am running linux.
I have a program writen with Qt 3.3 I want to re-write it using Qt-4.1 Designer. I would like my Qt 3 program ( in KDevelop 3 ) on one Desktop and the Qt4-Designer in another Desktop so I can toggle between them.
How can I load Qt4 designer direcely from a terminal and not screw up my Qt 3?.

Thanks for any help.

Codepoet
29th January 2006, 19:43
Call the designer with the whole path. On my system
Qt 3:
/usr/qt/3/bin/designer
Qt 4:
/usr/bin/designer

When you only type designer it depends on the order of the paths in the PATH environment variable. You can view it with
env | grep PATH

The same applies to all other tools like qmake, moc and uic.

impeteperry
30th January 2006, 15:18
Thanks Codepoet. I really am stupid. i thought I had looked in /usr/bin but I guess my 80 years is catching up with me.

impeteperry
1st February 2006, 23:08
OK, I have my qt4 designer up. I have my layout the way I want it
I don't see in qt4 where you load or develop the ".pro" file or the "main.cpp" file. that were available in Qt3.
I didn't see them in the "Getting Started" in the Qt4 Designer manual example.
What am I missing?

Everall
2nd February 2006, 09:42
have a look at this video :
http://www.trolltech.com/video/qt4/browser.html

Basically in QT4 you use your editor of your choice to make the pro and main.cpp file. There isn't an editor in QT4 anymore.

Cheers

impeteperry
2nd February 2006, 20:01
have a look at this video :
http://www.trolltech.com/video/qt4/browser.html

Basically in QT4 you use your editor of your choice to make the pro and main.cpp file. There isn't an editor in QT4 anymore.

Cheers
Thanks for the info.

pete

impeteperry
20th March 2006, 17:43
i'm back.
I have a label.ui, a label.h, a label.cpp and a main.cpp.
#include <QApplication>
#include "label.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Label label;
label.show();
return app.exec();
}which gives me a simple window with a title. Now I want to incorporate my label.ui file. following the example in the "docs"
#include <QApplication>

#include "ui_labels.h" // defines the Ui::MyForm struct
#include "label.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Label label;

Ui::label ui;
ui.setupUi(&label);

label.show();
return app.exec();
}
and when I run "qmake -project", "qmake labelform.pro" and "make" I get
main.cpp:28:59: error: ui_labels.h: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:36: error: ‘Ui’ has not been declared
main.cpp:36: error: expected `;' before ‘ui’
main.cpp:36: warning: statement has no effect
main.cpp:37: error: ‘ui’ was not declared in this scope
make: *** [main.o] Error 1
I am at a loss on how to handle these instructions
Like before, Qt Designer still writes out .ui files that contain the specification of an interface, and uic generates C++ code based on the .ui file. What has changed is that uic now generates a simple struct containing all the widgets and a setupUi() function that creates the widgets and layouts. The struct does not inherit from QObject and is entirely defined in a header file.
I would really appreciate some help. thanks

or is there an example that does this?

jacek
20th March 2006, 18:15
#include "ui_labels.h"
Shouldn't it be:
#include "ui_label.h"(remember to rerun qmake).


is there an example that does this?
http://doc.trolltech.com/4.1/designer-using-a-component.html#the-single-inheritance-approach

impeteperry
20th March 2006, 19:06
Thanks Jacek
I made the correction, ran qmake -project, qmake labelform.pro and make and got
main.cpp:37: error: ‘label’ is not a member of ‘Ui’
main.cpp:37: error: expected `;' before ‘ui’
main.cpp:38: error: ‘ui’ was not declared in this scope


do I have to add anything to "label.h" ?

jacek
20th March 2006, 20:00
do I have to add anything to "label.h" ?
No, the problem is with this line:
Ui::label ui;
Open that .ui file in the Designer, select your form in the "Object Inspector" and check the value of objectName property in "Property Editor". It should be that same as the part after Ui:: (i.e. in this case it should be label).

impeteperry
20th March 2006, 22:51
Thanks. it worked.!!!
how simple things are when you know what you are doiing.

Thanks again.

impeteperry
21st March 2006, 15:45
A new problem. In the "Evolution of Qt Designer" there are 3 methods of connecting a ".ui" file. The first of the three is the one you helped me with, but the other two both have a problem.
In the single-inheritance approach, you subclass the form's base class (QWidget or QDialog, for example), and include a private instance of the form's user interface object. For example:

#ifndef MYFORM_H
#define MYFORM_H

#include "ui_myform.h"

class MyForm : public QDialog
{
Q_OBJECT

public:
MyForm(QWidget *parent = 0) : QDialog(parent)
{ ui.setupUi(this);

private slots:
void on_inputSpinBox_valueChanged(int value);

private:
Ui::MyForm ui;
};

#endif it seems to be missing a "}". The third one is also missing one. This my attempt:
#ifndef LABEL_H
#define LABEL_H

#include "ui_label.h"
#include <QWidget>

class Label : public QWidget
{
Q_OBJECT

public:
Label(QWidget *parent = 0) : QWidget(parent)
{ ui.setupUi(this);

private slots:

private:
Ui::Label ui;
};
#endif and here is my message
label.cpp:30: error: ‘Label::Label(QWidget*)’ cannot be overloaded
label.h:35: error: with ‘Label::Label(QWidget*)’
label.cpp:34: error: expected `}' at end of input
label.h: In constructor ‘Label::Label(QWidget*)’:
label.h:36: error: ‘ui’ was not declared in this scope
label.h:38: error: expected primary-expression before ‘private’
label.h:38: error: expected `;' before ‘private’
label.cpp: At global scope:
label.cpp:34: error: expected unqualified-id at end of input
make: *** [label.o] Error 1
my "label.cpp" is
#include <QtGui>
#include "label.h"

Label::Label(QWidget *parent)
: QWidget(parent)
{
}


Thanks for any help.

jacek
21st March 2006, 16:14
it seems to be missing a "}".
Yes, that } should be there. Besides you can't implement the same method twice (you have implemented the constructor in both .h and .cpp file).

It should be:

label.h
#ifndef LABEL_H
#define LABEL_H

#include "ui_label.h"
#include <QWidget>

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

private:
Ui::Label ui;
};

#endif
label.cpp:
#include "label.h"

#include <QtGui>

Label::Label( QWidget *parent )
: QWidget( parent )
{
ui.setupUi( this );
}

PS. Next time, please, use [ code ] tags, instead of [ quote ] for code snippets.

impeteperry
21st March 2006, 20:12
Thanks, will do.

That did the job. I have now printed out the whole doc. wich I shall study in detail.
I have three other programs that I need to convert. All my programs thou on drastically differnt subjects use the same basic type of layout ( I hate "blender"'s complexity all though I use it ).
I really appreciate the help you have given me.

impeteperry
24th March 2006, 17:51
I am using te "books" demo that comes with qt4 as a guide.

I have all my widgets entered, layed out etc. As long as I don't set the whole shebang to a "layout on a grid" all is good except it doesn't "resize". If I do set it to a Grid, I just get a white box in the upper left corner.

The "books" demo has a container labeled "QWidget" which performs the function I want to do with the "layout on a grid". I can't find a "QWidget" in the "containers" list.
Any help would be appreciated

PS:
I have set up
edpform.cpp edpform.h edpform.ui main.cpp
as a template for my four programs. where I use a different "edpform.ui" for each program.
Any thoughts?

impeteperry
25th March 2006, 17:25
I don't know how, but I have solved my proklem