You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, June 12th 2012, 11:01am

Signals in a struct

Hi,

I'm trying to add the Q_OBJECT macro in a struct like this by using QtCreator :

Source code

1
2
3
4
5
6
7
8
9
10
    struct Area : public QObject {

      Q_OBJECT

      public :
        Scene* scene;
      
      signals :
        void readyToDraw(TDAbstractFigure*);
    };


whith others structs which inherit from Area like Circle :

Source code

1
2
3
4
5
    struct Circle : public Area {
 Q_OBJECT
      
      // ...
    };


But i have some errir :

Quoted

Circle.obj:-1: erreur : LNK2001: symbole externe non résolu "public: virtual struct QMetaObject const * __thiscall MyClass::Area::metaObject(void)const " (?metaObject@Area@MyClass@@UBEPBUQMetaObject@@XZ)
I've forgotten something ?

Thanks a lot :)

This post has been edited 1 times, last edit by "msarc" (Jun 12th 2012, 11:23am)


2

Tuesday, June 12th 2012, 12:59pm

Looks like you are building it incorrectly.

How are you moccing and compiling? What is your IDE? etc...
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Tuesday, June 12th 2012, 1:28pm

Thank you Amleto for you help.

I'm using QtCreator for my project.

My structures are declared in the public part of a header class like that :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class MyClass: public OtherClass
{
  Q_OBJECT

  public :

    struct Area : public QObject {

      public :
        Scene* scene;

//      signals :
//        void readyToDraw(TDAbstractFigure*);
    };

    struct Circle : public Area {

      public :
    };


But if i tried to add signals in Area struct with Q_OBJECT macro, it doesn't work correctly :s

4

Tuesday, June 12th 2012, 2:56pm

so pull them out of MyClass definition. It doesn't look like they belong there anyway.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

5

Tuesday, June 12th 2012, 3:22pm

Ok but actually, i have put them here to group my structures and avoid to create several classes ...

Where i can put them ?

Just outside myClas but in the same header ?

Thanks !

6

Tuesday, June 12th 2012, 4:13pm

"and avoid to create several classes"

Well you haven't avoided it - you still have several classes. You have avoided having separate headers.

They should all be in their own header imo, not in the same one.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

7

Tuesday, June 12th 2012, 4:58pm

Yes sure you are right!

Sorry for my wrong explanation.

Actually, with the context, i have :

1) Firstly, some classes to define some figures (Circle, Rectangle, ...) with their own behaviour in a scene (motion, edition, ...)

2) Secondly, i have my structs in which i save only the coordinates of my figures in another coordinates system.

I have voluntarly separate information with in first hand, the behaviour of my figures in my scene and on the other, the coordinates in another system.

As my structures contain only the coordinates in a system, i thought group the structs in the same file ...

What is your idea by keeping the separation (even if referenced figures in the two separate classes are the same) ? Create some other files for the coordinate system ? like this :

(behaviour in scene)
- CircleScn
- RectangleScn
- PolygonScn

(system coordinates)
- CircleG
- RectangleG
- PolygonG

seems good ?

Thanks a lot Amleto for your advices !

8

Tuesday, June 12th 2012, 6:25pm

I dont understand why you have separated the coordinates
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

9

Wednesday, June 13th 2012, 10:46am

Hi Amleto,

It's just to keep a separation between the scene and the other coordinate system.

In my example, the scene is just a way to display and interact with figures in the scene coordinate but actually my "real objects" are saved in the other coordinate system and exist with or without the scene..

10

Wednesday, June 13th 2012, 1:00pm

is there any interaction / connection between scene coords and 'other' coords?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

11

Wednesday, June 13th 2012, 1:10pm

The only interaction is a projection between the two coordinate systems.

Example :

- Initialy, i draw figure in my scene
- I want to save the game -> projection from the scene system of my figures to other system coordinate.
- Later, load the game -> projection from my other coordinate system to scene system and creation of the figures in the scene.

12

Wednesday, June 13th 2012, 5:38pm

so one uniquely defines the other. if you are keeping both coords in memory then it is redundant and a possible cause of bugs by inadvertently using and 'old' value.

I think you should not be storing 'other' coords at all. You should have an algorithm to convert to/from 'other', but you should not be storing them anywhere as they appear to be worthless in your application?
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

13

Thursday, June 14th 2012, 10:01am

Actually the coords of my figures in the other system can be used without the scene to make some calculation.

It would be weird to keep my scene's figures if i don't need them.

Even if we create the first time figures in the scene, it seems like the scene plays a secondary role, just a way to display my figure but it's all.

Nevertheless, as soon as i edit a figure in my scene or in my other system, the projection is done.

I could have done as you suggest to do it but i really prefere separate the two objects with on the first hand the data coord in the real world and on the other, the figures in my scene..

You really advice my against this way ?

Thnaks Amleto !

14

Thursday, June 14th 2012, 12:01pm

"Actually the coords of my figures in the other system can be used without the scene to make some calculation."
Ok, I admit you will need access to those coords, then.

"It would be weird to keep my scene's figures if i don't need them."
Agree
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.