You are not logged in.

a_Guest_who_WONDERS

Unregistered

1

Wednesday, October 13th 2004, 9:59am

BC: How to get own definiton in .h file

Hello all friendly QT Programmers,

my problem regards to the automatic made class header file .h of a .ui file.

I need in my (from uic generated) .h another QString variable.

Is there a way to tell QtDesigner to include a statement as "QString commands;" in the public part of the class? Do I have to make a custom widget, for getting another QString in the public part?

Currently I'm waiting for compile error:

---

form1.ui.h: In method `void Progstarter::start_mozilla()':
form1.ui.h:52: `class Dialog' has no member named `commands'

---

Then I add the " QString commands " manually to the class Dialog .h file. After recompile everything works fine.

But that can't be goblet of cleverness...

Please give me a hint

Merry Wishes

.aGuestWhoneedsHELP

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Wednesday, October 13th 2004, 10:21am

RE: BC: How to get own definiton in .h file

You could subclass your dialog class.

aGuestwhoNeedsHelp

Unregistered

3

Wednesday, October 13th 2004, 10:28am

Yes, I thought of something like this.

But how is it done in practice ?

I know how to inheritate classes in C++ , but I do not know where to affix my lever in QT.

Do I need after subclassing manual Makefile?
In which file do I have to put the subclass information in?

Information about my files:

startdialog.ui.h
startdialog.ui

In which of the above do I have to put the information in?

Would be nice if could touch me by the hand.

.AGuestwhoNeedsHelp

ZX_SA

Trainee

  • "ZX_SA" is male

Posts: 90

Location: Stellenbosch, South Africa

Occupation: Software Engineer

  • Send private message

4

Wednesday, October 13th 2004, 10:42am

If you're designing a gui with designer and just want to add an extra variable to the gui class, then it's actually very simple:

Open the .ui file in designer. Go to the "Object Explorer" window and select the "Members"-tab. Now scroll down to where you see the heading "Class Variables". Right click on it and select edit. A new dialog window opens where you can add new variables to the gui class. They'll automatically be added to the uic generated .h file and you can safely use them in the .ui.h file.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

5

Wednesday, October 13th 2004, 11:00am

ZX_SA have already posted a simplier solution, but anyway:

Lets assume that you have a StartDialogStub class as a startdialogstub.ui file.

uic will generate startdialogstub.h file with definition of this class. You can easily create a new class,
say StartDialog which inherits the StartDialogStub:

Source code

1
2
3
4
5
6
7
8
#include "startdialogstub.h"

class StartDialog : public StartDialogStub
{
   Q_OBJECT:
   public:
      ... // you have to add proper method declarations here
}
Then you have to add your code to startdialog.cpp file.

To compile your project you have to add those two new files to your .pro file (one in HEADERS and
other in SOURCES list) and generate new Makefile by invoking "qmake".

I prefer this method over the .ui.h files, because this way I can generate proper documentation of the
StartDialog class using Doxygen (there might be a better solution, but this works ;) ).

aGuestwhoGotHelp

Unregistered

6

Thursday, October 14th 2004, 10:12am

Have very merry thanks.

Both solutions are so intelligent, as I always thought of QT !!

Thank you ZX_SA, thank you jacek.

I think I'll prefer jaceks solution. :)


.aGuestwhoGOTHelp