Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Compiler Problems (Qt 5.1,GCC compiler x86 64 bits)
Forum Updated to NodeBB v4.3 + New Features

[Solved]Compiler Problems (Qt 5.1,GCC compiler x86 64 bits)

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Charlie_Hdz
    wrote on 28 Mar 2014, 02:10 last edited by
    #1

    Hi there.

    I spend some time with a problem about my compiler.

    I have my code such this:

    @#ifndef CEDGE_H
    #define CEDGE_H
    #include "cgraphmanager.h"
    #include <QtCore>
    #include <QtGui>

    class CEdge
    {
    friend class CGraphManager;

    public:
    CGraphManager* m_pGraphManager;

     virtual void DrawEdge(QPaintEvent *event);
    
    unsigned long long GetKey()const;
    
    unsigned long GetKeyFirst()const;
    
    unsigned long GetKeySecond()const;
    

    protected:
    union
    {
    struct
    {
    unsigned long m_ulIDFirst;
    unsigned long m_ulIDSecond;
    };
    unsigned long long m_ullID;
    };

    CEdge();
    virtual~CEdge();
    

    };

    #endif // CEDGE_H
    @

    and the .cpp:

    @#include "cedge.h"
    #include "cvertex.h"

    CEdge::CEdge()
    {
    }

    CEdge::~CEdge(){

    }

    void CEdge::DrawEdge(QPaintEvent *event){

    QPainter EdgePainter=new QPainter();
    
    CVertex* pVFirst,*pVSecond;
    pVFirst=m_pGraphManager->CreateVertex(m_ulIDFirst);
    pVSecond=m_pGraphManager->CreateVertex(m_ulIDSecond);
    
    EdgePainter.drawLine(pVFirst->m_fx,pVFirst->m_fy,pVSecond->m_fx,pVSecond->m_fy);
    
     //Implementar un metodo de utensilio para dibujar las flechas. DrawArrows(bool) permite o no la visualizacion de flechas
    

    }

    unsigned long long CEdge::GetKey()const
    {
    return m_ullID;
    }

    unsigned long CEdge::GetKeyFirst()const
    {
    return m_ulIDFirst;
    }

    unsigned long CEdge::GetKeySecond()const
    {
    return m_ulIDSecond;
    }
    @

    Is one of much class and the easiest, and the .pro of the static library is something like this:

    @#-------------------------------------------------

    Project created by QtCreator 2014-03-19T23:25:37

    #-------------------------------------------------

    QT += core gui
    TARGET = GraphLib
    TEMPLATE = lib
    CONFIG += staticlib
    CONFIG += c++11
    QMAKE_CXXFLAGS += -std=c++11

    SOURCES += graphlib.cpp
    cvertex.cpp
    cedge.cpp
    cgraph.cpp
    cgraphmanager.cpp

    HEADERS += graphlib.h
    cvertex.h
    cedge.h
    cgraph.h
    cgraphmanager.h
    unix:!symbian {
    maemo5 {
    target.path = /opt/usr/lib
    } else {
    target.path = /usr/lib
    }
    INSTALLS += target
    }

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/release/ -lGraphLib
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/debug/ -lGraphLib
    else:unix: LIBS += -L$$OUT_PWD/ -lGraphLib

    INCLUDEPATH += $$PWD/
    DEPENDPATH += $$PWD/

    win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/release/GraphLib.lib
    else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/debug/GraphLib.lib
    else:unix: PRE_TARGETDEPS += $$OUT_PWD/libGraphLib.a
    @

    Sometimes my project make me ones error at build time like

    undefined reference to vtable for CVertex

    or

    say me that the QtGui dont exist.

    But the rare issues is that is intermittent. I restart my computer, open again Qt and build the project and the errors dont show.

    Only if is rebuild all it is when the issues appear again

    Any idea about this problem?

    Thank You

    Kind Regards,
    Enrique Hernandez
    gearstech.com.mx
    chernandez@gearstech.com.mx

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 28 Mar 2014, 03:02 last edited by
      #2

      bq. undefined reference to vtable for ...

      I've seen this error in two cases.

      If you forget to add widgets to QT (QT += widgets) in Qt5

      If you declare class and implemented this class in the same file and forget to include .moc file at the end of the file.

      Also you can take a look "on these questions and answers":http://qt-project.org/search?search=undefined+reference+to+vtable+for

      If you use Qt5 then the second error can be related to the fact that you forget to add widgets to QT variable.

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on 28 Mar 2014, 03:11 last edited by
        #3

        [quote author="andreyc" date="1395975720"]I've seen this error in two cases.

        If you forget to add widgets to QT (QT += widgets) in Qt5

        If you declare class and implemented this class in the same file and forget to include .moc file at the end of the file.[/quote]Please do not manually include .moc files! You should let the Qt build system take care of it.

        There are 2 common reasons for "undefined reference to vtable" in classes that inherit QObject:

        You declared your class in the .cpp file instead of the .h file.

        You added the Q_OBJECT macro to your class, but didn't update your Makefile.

        The solution to these scenarios is: Make sure your class is declared in a .h file (not a .cpp) file, and then run qmake.

        Is CVertex a QObject?

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on 28 Mar 2014, 03:18 last edited by
          #4

          bq. Please do not manually include .moc files! Just declare your class in a header, and let the Qt build system take care of the rest.

          Agree that it is not good idea.
          I hit such error once when I deleted the following line from the end of tst_MyTest.cpp
          @
          #include "tst_MyTest.moc"
          @

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on 28 Mar 2014, 03:32 last edited by
            #5

            [quote author="andreyc" date="1395976682"]bq. Please do not manually include .moc files! Just declare your class in a header, and let the Qt build system take care of the rest.

            Agree that it is not good idea.
            I hit such error once when I deleted the following line from the end of tst_MyTest.cpp
            @
            #include "tst_MyTest.moc"
            @
            [/quote]OK, test cases are a bit different. :) That's the one and only place where you are supposed to manually a .moc file (as "documented":http://qt-project.org/doc/qt-5/qttestlib-tutorial1-example.html ).

            Charlie_Hdz should not do this though, since he's not writing a test.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Charlie_Hdz
              wrote on 28 Mar 2014, 17:39 last edited by
              #6

              Thank you very much JKSH and amdreyc

              En effect, Cvertex is not a Q Object.

              My problems right now is the following points:

              •  With that code the compiler make intermitent error ( I mean sometimes it does  sometimes not) , since i started working on Qt in linux with the compiler GCC compiler x86 64 bits I've had much problems but i always find the answer.Whatever , for this reason i think is something based on the setting of the compiler or the compiler itself.( If you have a tip about how should be setting the compiler).
                
              •    In this moment, im learning how to draw primitive shapes and i had this method:
                

              @void CEdge::Draw(QPainterEvet event){
              QPainter painter;
              painter.setPen(Qt::black);
              CVertex
              pVFirst,*pVSecond;
              pVFirst=m_pGraphManager->CreateVertex(m_ulIDFirst);
              pVSecond=m_pGraphManager->CreateVertex(m_ulIDSecond);

              painter.drawLine(pVFirst->m_fx,pVFirst->m_fy,pVSecond->m_fx,pVSecond->m_fy);
              

              }
              @

              were Cvertex is other class of the static library.

              So this method is from a class of a static library were are Stl containers that store the points where the lines and circles in a window (widgets) will be drawn, of course this library does not inherit from QObject and not draw anything on it.

              Im confuse about if possible implement the QPainter in this method or I have to create a method of that widget and then call this method CEdge to access to the data of the container , in short I'm drawing a graph in Qt.

              Any idea is welcome.

              Kind Regards,
              Enrique Hernandez
              gearstech.com.mx
              chernandez@gearstech.com.mx

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on 28 Mar 2014, 18:40 last edited by
                #7

                Hi,
                perhaps it's because you're not calling begin() and end() on your QPainter class.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Charlie_Hdz
                  wrote on 29 Mar 2014, 02:30 last edited by
                  #8

                  hskoglund into the constructor and destructor of the class?

                  Kind Regards,
                  Enrique Hernandez
                  gearstech.com.mx
                  chernandez@gearstech.com.mx

                  1 Reply Last reply
                  0
                  • hskoglundH Offline
                    hskoglundH Offline
                    hskoglund
                    wrote on 29 Mar 2014, 07:23 last edited by
                    #9

                    No, right after you create your QPainter instance, like this:

                    QPainter EdgePainter=new QPainter();  
                    EdgePainter.begin   lots of DrawLines    EdgePainter.end
                    
                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Charlie_Hdz
                      wrote on 31 Mar 2014, 00:48 last edited by
                      #10

                      All right hskoglund Thank you.

                      Kind Regards,
                      Enrique Hernandez
                      gearstech.com.mx
                      chernandez@gearstech.com.mx

                      1 Reply Last reply
                      0

                      1/10

                      28 Mar 2014, 02:10

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved