[SOLVED]Widget connection doubt



  • Hi!

    I have a Widget working with OpenGL properly and i create a Camera Object and i´m trying connect some signals form my Widget to my Camera Object.

    In my main.cpp i have the following code:

    CI3DCamera *pCam = new CI3DCamera;

    GLWidget widget(0);
    widget.resize(640, 480);

    QObject::connect(&widget,&GLWidget::initializeGL,pCam,&CI3DCamera::Inicializa);

    widget.show();
    return a.exec();

    But....i receive the following error:
    main.cpp
    C:\Qt\Qt5.1.0\5.1.0\msvc2012_64_opengl\include\QtOpenGL/qgl.h(364) : error C2440: 'initializing' : cannot convert from 'void' to 'int'
    Expressions of type void cannot be converted to other types
    c:\qt\qt5.1.0\5.1.0\msvc2012_64_opengl\include\qtcore\qobject.h(220) : see reference to function template instantiation 'void QGLWidget::qt_check_for_QOBJECT_macro<GLWidget>(const T &) const' being compiled
    with
    [
    T=GLWidget
    ]
    ..\INS2\main.cpp(23) : see reference to function template instantiation 'QMetaObject::Connection QObject::connect<void(__cdecl GLWidget::* )(void),void(__cdecl CI3DCamera::* )(void)>(const GLWidget ,Func1,const CI3DCamera ,Func2,Qt::ConnectionType)' being compiled
    with
    [
    Func1=void (__cdecl GLWidget::
    )(void),
    Func2=void (__cdecl CI3DCamera::
    )(void)
    ]
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile.Debug [debug\main.obj] Error 2
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile [debug] Error 2
    17:11:05: The process "C:\Qt\Qt5.1.0\Tools\QtCreator\bin\jom.exe" exited with code 2.
    Error while building/deploying project INS2 (kit: Desktop Qt 5.1.0 MSVC2012 OpenGL 64bit)
    When executing step 'Make'
    17:11:05: Elapsed time: 00:03.

    Anyone know why these error happen, and how to solve it?


  • Lifetime Qt Champion

    Hi,

    I'm not yet a Qt 5 expert but judging from your code and the error message:

    you don't have the Q_OBJECT macro in your GLWidget declaration

    you are trying to connect initializeGL which is not a signal, it's a function you have to implement

    Hope it helps



  • Hi!
    Thanks so Musch for your help.
    I made the changes informed , but i start receive another error.

    This is My Widget class:
    @
    class GLWidget : public QGLWidget
    {

    Q_OBJECT
    

    public:
    GLWidget(QWidget *parent);
    ~GLWidget();
    public:
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void timerEvent(QTimerEvent *) { update(); }
    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
    signals:
    void Inicializa();
    void Renderiza();
    public:
    int timerId;
    };
    @

    This is my Camera Class:
    @
    class CI3DCamera : public QObject
    {
    Q_OBJECT

    public:

    explicit CI3DCamera(QObject *parent = 0);
    
    float     I3D_Velocidade     ;// Velocidade da camera
    float     I3D_Intervalo      ;// Intervalo dos Frames
    
    CI3DVetor    I3D_CameraPos         ;// Posicao da camera
    CI3DVetor    I3D_CameraView        ;// Visão da Câmera
    CI3DVetor    I3D_CameraUp          ;// Direcao Superior
    CI3DVetor    I3D_CameraStrafe      ;// Strafe
    
    float     i3dFramesPorSegundo    ;
    float     i3dUltimoTempo   ;
    float     i3dTempoFrame          ;
    
    int       AtTela;
    int       LgTela;
    

    signals:
    void Inicializa ( );

    public slots:

      void SetaCamera            (float i3dPosicaoX          ,
                                  float i3dPosicaoY          ,
                                  float i3dPosicaoZ          ,
                                  float i3dViewX             ,
                                  float i3dViewY             ,
                                  float i3dViewZ             ,
                                  float i3dUpX               ,
                                  float i3dUpY               ,
                                  float i3dUpZ               );
      void PegaDirecao           (float &i3dPosicaoX         ,
                                  float &i3dPosicaoY         ,
                                  float &i3dPosicaoZ         );
    
      CI3DVetor PegaDirecao      (                           );
    
      void MoverCamera           (float i3dDirecao           );
    
      void AtualizaCamera        (float xDir                 ,
                                  float yDir                 ,
                                  float zDir                 ,
                                  float dir                  );
      void Rodar                 (float i3dAnguloDirecao     ,
                                  float i3dPosicaoX          ,
                                  float i3dPosicaoY          ,
                                  float i3dPosicaoZ          );
    
      void MapeiaMouse           (                           );
      void CalculaStrafe         (                           );
      void CameraStrafe          (float        i3dDirecao    );
      void PosicionaCamera       (                           );
      void CalculaTempo          (                           );
      void ResetaCamera          (                           );
      void CalculaPerspectiva    (float i3dProx,float i3dDist);
    

    };
    @

    The main have this code:
    @
    CI3DCamera pCam;

    GLWidget widget(0);
    widget.resize(640, 480);
    //widget.showFullScreen();
    
    QObject::connect(&widget,&GLWidget::Inicializa,&pCam,&CI3DCamera::Inicializa);
    
    widget.show();
    return a.exec&#40;&#41;;
    

    @

    But i start receive the following error:
    main.obj : error LNK2019: unresolved external symbol "public: void __cdecl CI3DCamera::Inicializa(void)" (?Inicializa@CI3DCamera@@QEAAXXZ) referenced in function main
    main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const GLWidget::staticMetaObject" (?staticMetaObject@GLWidget@@2UQMetaObject@@B)
    glwidget.obj : error LNK2019: unresolved external symbol "public: static struct QMetaObject const GLWidget::staticMetaObject" (?staticMetaObject@GLWidget@@2UQMetaObject@@B) referenced in function "public: void __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Xran(void)const " (?_Xran@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAXXZ)
    glwidget.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl GLWidget::metaObject(void)const " (?metaObject@GLWidget@@UEBAPEBUQMetaObject@@XZ)
    glwidget.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl GLWidget::qt_metacast(char const *)" (?qt_metacast@GLWidget@@UEAAPEAXPEBD@Z)
    glwidget.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl GLWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@GLWidget@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    debug\INS2.exe : fatal error LNK1120: 6 unresolved externals
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile.Debug [debug\INS2.exe] Error 1120
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile [debug] Error 2
    18:53:19: The process "C:\Qt\Qt5.1.0\Tools\QtCreator\bin\jom.exe" exited with code 2.
    Error while building/deploying project INS2 (kit: Desktop Qt 5.1.0 MSVC2012 OpenGL 64bit)
    When executing step 'Make'
    18:53:19: Elapsed time: 00:04.

    Can you help me , please?

    Kind Regards.


  • Lifetime Qt Champion

    Did you run qmake after adding the Q_OBJECT macro ?

    Also, are you sure you want to connect two signals together ?



  • Yest i compile the code after, and the message change as i show.

    I change the:
    @void Inicializa ( );@ Camera member to slot

    The error still the same , i dont know why but it seems the framework simply doesn untderstand that is a member there...



  • Just for instance, when you ask for qmake is compile code, is it?
    Becouse i´m using MSVC compiler, automatcally configured when i install QC...



  • Hey!
    I run a option on the Build Menu with qMake , and runs fine...then wneh i try compile the code again it seems something change... i will check it out, but i still receiving errors...
    allways when i change the code i need run qMake?

    Kind Regards, and thanks so much for your help!



  • Hi SGaist !

    It seems is a problem with other places with my code...
    when i start run qMake before Build it...the things start to work.
    I will fix the other parts of my code.

    Thanks so much for your help!



  • Hi!

    It seems the compilations are working now...but i´m receiving this error now:

    moc_glwidget.obj : error LNK2005: "public: void __cdecl GLWidget::Inicializa(void)" (?Inicializa@GLWidget@@QEAAXXZ) already defined in glwidget.obj
    moc_glwidget.obj : error LNK2005: "public: void __cdecl GLWidget::Renderiza(void)" (?Renderiza@GLWidget@@QEAAXXZ) already defined in glwidget.obj
    debug\INS2.exe : fatal error LNK1169: one or more multiply defined symbols found
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile.Debug [debug\INS2.exe] Error 1169
    jom: C:\William\PUC-pr\professor\Programa‡Æo Engine\Projeto - Insane Engine\Qt\build-INS2-Desktop_Qt_5_1_0_MSVC2012_OpenGL_64bit-Debug\Makefile [debug] Error 2
    20:18:40: The process "C:\Qt\Qt5.1.0\Tools\QtCreator\bin\jom.exe" exited with code 2.
    Error while building/deploying project INS2 (kit: Desktop Qt 5.1.0 MSVC2012 OpenGL 64bit)
    When executing step 'Make'
    20:18:40: Elapsed time: 00:09.

    It seems the members i put on my widget declaration are not in the correct place??? what is moc_glwidget.obj ???



  • Hi!

    I Change the approach (making a instance of my Camera inside the Widget) , and using qMake , than my code works fine!

    Thanks so much for the help!

    Kind Regards.


  • Lifetime Qt Champion

    You're welcome !

    Don't forget to update your thread's title prepending solved so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.