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



  • 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



  • 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.


  • Moderators

    [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?



  • 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"
    @


  • Moderators

    [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.



  • 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.



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



  • hskoglund into the constructor and destructor of the class?



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

    QPainter EdgePainter=new QPainter();  
    EdgePainter.begin   lots of DrawLines    EdgePainter.end
    


  • All right hskoglund Thank you.


Log in to reply
 

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