Change some code in ui_xxx.h
-
wrote on 30 Mar 2011, 04:02 last edited by
In ui_myclass.h we can find these lines:
@namespace UI {
class MyClass : public Ui_MyClass {}
} // namespace Ui@I think we can have a better way to do this. That's my code:
@namespace UI {
typedef Ui_MyClass MyClass;
} // namespace Ui@Both of them do the same things. But the former will call one more constructor than the latter.
I don't know why qt doesn't use the latter. It's much easier. -
wrote on 30 Mar 2011, 04:35 last edited by
I hope you know, that ui_xxx.h is recreated by UIC?
It dioes not make sense to change in that file. -
wrote on 30 Mar 2011, 07:45 last edited by
of cause i know. i hope uic can generate my code in the future :) i think mine is better
[quote author="Gerolf" date="1301459734"]I hope you know, that ui_xxx.h is recreated by UIC?
It dioes not make sense to change in that file.[/quote] -
wrote on 30 Mar 2011, 07:56 last edited by
In that case, I suggest you write a patch for uic, and submit a merge request for it.
-
wrote on 30 Mar 2011, 08:33 last edited by
It would mean you cannot do a
@class MyClass;@
definition somewhere in a header, and I imagine there would be no extra constructors called once the app was compiled in release... but apart from that, it is neater.
-
wrote on 30 Mar 2011, 10:19 last edited by
Hi Jori,
you just did a predefine, not a class definition.
What UIC does is really creating a class.@
class MyClass : public Ui_MyClass {}
@is different from
@
class MyClass;
@In your case, the class must be defined somewhere else.
-
wrote on 30 Mar 2011, 10:54 last edited by
A forward declaration of a class (to avoid #including the header) is not possible with a typedef.
In a header:
@
class Foo {
public:
Foo() { }
~Foo() { }int foobar;
};
typedef Foo FooAlias;
@and later on in another header:
@
class FooAlias;class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
FooAlias *f;
};
@and in the implementation of the MainWindow:
@
#include "mainwindow.h"
#include "foo.h"
@If you try to compile the .cpp of the MainWindow class you get an error message like this:
@
foo.h:9: error: conflicting declaration 'typedef class Foo FooAlias'
mainwindow.h:1: error: 'struct FooAlias' has a previous declaration as 'struct FooAlias'
@ -
wrote on 30 Mar 2011, 12:27 last edited by
Gerolf, I was saying what Volker said, but possibly less eloquently! ;)
-
wrote on 21 Apr 2011, 10:24 last edited by
i test it with gcc 3.3. Forward declaration are supported.
[quote author="Volker" date="1301482447"]A forward declaration of a class (to avoid #including the header) is not possible with a typedef.
In a header:
@
class Foo {
public:
Foo() { }
~Foo() { }int foobar;
};
typedef Foo FooAlias;
@and later on in another header:
@
class FooAlias;class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
FooAlias *f;
};
@and in the implementation of the MainWindow:
@
#include "mainwindow.h"
#include "foo.h"
@If you try to compile the .cpp of the MainWindow class you get an error message like this:
@
foo.h:9: error: conflicting declaration 'typedef class Foo FooAlias'
mainwindow.h:1: error: 'struct FooAlias' has a previous declaration as 'struct FooAlias'
@[/quote] -
wrote on 21 Apr 2011, 11:52 last edited by
[quote author="ibingow" date="1303381454"]i test it with gcc 3.3. Forward declaration are supported.
[/quote]Forward declaration in general is supported, yes. But not the construct mentioned above.
You can try yourself, this is a complete example:
------ foo.h ------
@
#ifndef FOO_H
#define FOO_Hclass Foo {
public:
Foo() { }
~Foo() { }int foobar;
};
typedef Foo FooAlias;
#endif // FOO_H
@------ using.h ------
@
#ifndef USING_H
#define USING_Hclass FooAlias;
class UsingFoo
{public:
explicit UsingFoo();
~UsingFoo();private:
FooAlias *f;
};#endif // USING_H
@------ using.cpp ------
@
#include "using.h"
#include "foo.h"UsingFoo::UsingFoo()
{
f = new FooAlias;
}UsingFoo::~UsingFoo()
{}
@------ main.cpp ------
@
#include "using.h"int main(int argc, char *argv[])
{
UsingFoo uf;
return 0;
}
@Compile with
@
g++ -c -o main.o main.cpp
g++ -c -o using.o using.cpp
g++ -o typedeftest main.o using.o
@It definitely fails with gcc 4.2.x and 3.4.x, all with the very same error message I posted earlier.
-
wrote on 5 Jul 2011, 14:27 last edited by
Yes, you're right. But it's strange that my gcc 3.3.1 can compile your example without warning and error.
-
wrote on 5 Jul 2011, 14:41 last edited by
[quote author="ibingow" date="1309876061"]Yes, you're right. But it's strange that my gcc 3.3.1 can compile your example without warning and error. In fact, in your example, we can write UsingFoo like that
[/quote]I just don't believe you. My code fails with gcc 3.2.2 with the same error messages. It is very unlikely that it failed on 3.2.x, compiled on 3.3.x and failed again on 3.4.x. You must have modified the code or tweaked some compiler switches.