Results 1 to 5 of 5

Thread: Warning and error

  1. #1
    Join Date
    Aug 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Warning and error

    When I compile my program I get some warnings and a ld error. What am I wrong?
    Qt Code:
    1. #ifndef ABSTRACTLOCATED_H
    2. #define ABSTRACTLOCATED_H
    3.  
    4. /**
    5.  * @brief This class is the base class of any non-movable objects in 2D space (without full implementation)
    6.  * @author amreo
    7.  * @version 0.1
    8.  * @since 0.4
    9.  */
    10. class AbstractLocated
    11. {
    12. public:
    13.  
    14. /**
    15.   * @brief Return the X coordinate
    16.   * @return X coordinate
    17.   */
    18. virtual int x() const = 0;
    19. /**
    20.   * @brief Return the Y coordinate
    21.   * @return Y coordinate
    22.   */
    23. virtual int y() const = 0;
    24.  
    25. /**
    26.   * @brief Check if the location are equal
    27.   * @param First location
    28.   * @param Second location
    29.   * @return True if are in the same location (x and y), else false
    30.   */
    31. static bool isLocationEqual(const AbstractLocated& loc1, const AbstractLocated& loc2)
    32. { return loc1.x() == loc2.x() && loc1.y() == loc2.y(); }
    33.  
    34. /**
    35.   * @brief Check if the location are equal
    36.   * @param Second location
    37.   * @return True if are in the same location (x and y), else false
    38.   */
    39. bool operator ==(const AbstractLocated& loc2) const
    40. { return x() == loc2.x() && y() == loc2.y(); }
    41.  
    42. /**
    43.   * @brief Check if the location are inequal
    44.   * @param Second location
    45.   * @return True if are in the same location (x and y), else false
    46.   */
    47. bool operator !=(const AbstractLocated& loc2) const
    48. { return x() != loc2.x() || y() != loc2.y(); }
    49. };
    50.  
    51. #endif // ABSTRACTLOCATED_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef ABSTRACTMOVABLE_H
    2. #define ABSTRACTMOVABLE_H
    3. #include <QObject>
    4. #include "abstractlocated.h"
    5.  
    6. /**
    7.  * @brief This class is the base class of any movable objects in 2D space (without full implementation)
    8.  * @author amreo
    9.  * @version 0.1
    10.  * @since 0.4
    11.  */
    12. class AbstractMovable : virtual public AbstractLocated, public QObject
    13. {
    14. public:
    15.  
    16. /**
    17.   * @brief Move the coordinte by the offset loc
    18.   * @param offset x and y
    19.   */
    20. AbstractMovable& operator >>(const AbstractLocated& loc) { move(loc); return *this; }
    21. /**
    22.   * @brief Move the coordinte by the offset -loc
    23.   * @param offset x and y
    24.   */
    25. AbstractMovable& operator <<(const AbstractLocated& loc) { move(-loc.x(), -loc.y()); return *this; }
    26.  
    27. signals:
    28. /**
    29.   * @brief This signal is emitted whenever the location is changed
    30.   * @param New location
    31.   */
    32. void locationChanged(const AbstractLocated& newLocation);
    33.  
    34. public slots:
    35. /**
    36.   * @brief Set the coordinate X
    37.   * @param New coordinte X
    38.   */
    39. virtual void setX(int x) = 0;
    40. /**
    41.   * @brief Set the coordinate Y
    42.   * @param New coordinte Y
    43.   */
    44. virtual void setY(int y) = 0;
    45. /**
    46.   * @brief Set the coordinate x and y
    47.   * @param New coordinate x
    48.   * @param New coordinate y
    49.   */
    50. virtual void setMovable(int x, int y) = 0;
    51. /**
    52.   * @brief Set the coordinate x and y from loc
    53.   * @param Located object
    54.   */
    55. inline void setMovable(const AbstractLocated& loc) { setMovable(loc.x(), loc.y()); }
    56.  
    57. /**
    58.   * @brief Move the coordinate by offset
    59.   * @param offset x
    60.   * @param offset y
    61.   */
    62. inline void move(int offsetX, int offsetY) { setMovable(this->x()+offsetX, this->y()+offsetY); }
    63. /**
    64.   * @brief Move the coordinate by the offset
    65.   * @param offset X and Y
    66.   */
    67. inline void move(const AbstractLocated& offset) { setMovable(this->x()+offset.x(), this->y()+offset.y()); }
    68.  
    69.  
    70. };
    71.  
    72. #endif // ABSTRACTMOVABLE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef LOCATED_H
    2. #define LOCATED_H
    3.  
    4. #include "src_global.h"
    5. #include "abstractlocated.h"
    6.  
    7. /**
    8.  * @brief This class is the base class of any non-movable objects in 2D space
    9.  * @author amreo
    10.  * @version 0.2
    11.  * @since 0.1
    12.  */
    13. class SRCSHARED_EXPORT Located : public virtual AbstractLocated
    14. {
    15.  
    16. public:
    17. /**
    18.   * @brief Create a new instance of fixed position from located object
    19.   * @param Located object
    20.   */
    21. Located(const AbstractLocated& loc) : _x(loc.x()), _y(loc.y()) {}
    22. /**
    23.   * @brief Copy costructor
    24.   * @param Located object
    25.   */
    26. Located(const Located& loc) : _x(loc.x()), _y(loc.y()) {}
    27.  
    28. /**
    29.   * @brief Return the X coordinate
    30.   * @return X coordinate
    31.   */
    32. inline int x() const { return _x; }
    33. /**
    34.   * @brief Return the Y coordinate
    35.   * @return Y coordinate
    36.   */
    37. inline int y() const { return _x; }
    38.  
    39. protected:
    40. /**
    41.   * @brief Coordinate x
    42.   */
    43. int _x;
    44. /**
    45.   * @brief Coordinate y
    46.   */
    47. int _y;
    48.  
    49. /**
    50.   * @brief Create a new instance of fixed position
    51.   * @param Coordinate x
    52.   * @param Coordinate y
    53.   */
    54. Located(int x = 0, int y = 0) : _x(x), _y(y) {}
    55. };
    56.  
    57. #endif // LOCATED_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MOVABLE_H
    2. #define MOVABLE_H
    3. #include "abstractmovable.h"
    4. #include "located.h"
    5.  
    6. /**
    7.  * @brief This class is the base class of any movable objects in 2D space
    8.  * @author amreo
    9.  * @version 0.2
    10.  * @since 0.1
    11.  */
    12. class Movable : virtual public Located, virtual public AbstractMovable
    13. {
    14. public:
    15. /**
    16.   * @brief Create a new instance of movable position from located object
    17.   * @param Located object
    18.   */
    19. explicit Movable(const AbstractMovable& loc) : Located(loc) {}
    20. /**
    21.   * @brief Create a new instance of movable position from located object
    22.   * @param Located object
    23.   */
    24. explicit Movable(const Movable& loc) : Located(loc) {}
    25.  
    26. /**
    27.   * @brief Set the coordinate X
    28.   * @param New coordinte X
    29.   */
    30. inline void setX(int x) {_x = x; emit locationChanged(*this); }
    31. /**
    32.   * @brief Set the coordinate Y
    33.   * @param New coordinte Y
    34.   */
    35. inline void setY(int y) {_y = y; emit locationChanged(*this); }
    36. /**
    37.   * @brief Set the coordinate x and y
    38.   * @param New coordinate x
    39.   * @param New coordinate y
    40.   */
    41. inline void setMovable(int x, int y) {_x = x; _y = y; emit locationChanged(*this); }
    42.  
    43. protected:
    44.  
    45. /**
    46.   * @brief Create a new instance of movable position
    47.   * @param Coordinate x
    48.   * @param Coordinate y
    49.   */
    50. Movable(int x = 0, int y = 0) : Located(x,y) {}
    51. };
    52.  
    53. #endif // MOVABLE_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef COORD_H
    2. #define COORD_H
    3. #include "movable.h"
    4. #include <QPoint>
    5.  
    6. /**
    7.  * @brief This class rappresent a 2D coord
    8.  * @author amreo
    9.  * @version 0.2
    10.  * @since 0.1
    11.  */
    12. class Coord : public virtual Movable
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. /**
    18.   * @brief Costructor of coord
    19.   * @param Coordinate X
    20.   * @param Coordinate Y
    21.   * @param Parent object
    22.   */
    23. Coord(int x = 0, int y = 0) : Movable(x,y) {}
    24.  
    25. /**
    26.   * @brief Costructor of coord
    27.   * @param point
    28.   */
    29. explicit Coord(const QPoint& point) : Movable(point.x(), point.y()) {}
    30. /**
    31.   * @brief Copy costructor of coord
    32.   * @param location
    33.   */
    34. Coord(const Coord& loc) : Movable(loc) {}
    35.  
    36. // /**
    37. // * @brief Sum the left and the right
    38. // * @param left
    39. // * @param right
    40. // * @return the sum of left and right
    41. // */
    42. // static inline Coord sum(const AbstractLocated& left, const AbstractLocated& right)
    43. // { return Coord(left.x()+right.x(), left.y()+right.y()); }
    44.  
    45. signals:
    46.  
    47. public slots:
    48.  
    49. };
    50.  
    51. #endif // COORD_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "coord.h"
    2. int main()
    3. {
    4. Coord l(0,0);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Errors/Warnings:
    Qt Code:
    1. In file included from ../build/moc/moc_coord.cpp:9:0:
    2. ../build/moc/../../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
    3. ../build/moc/../../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
    4. Coord(const Coord& loc) : Movable(loc) {}
    5. ^
    6.  
    7. In file included from ../../gridb/test/tests.h:8:0,
    8. from ../../gridb/test/main.cpp:2:
    9. ../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
    10. ../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
    11. Coord(const Coord& loc) : Movable(loc) {}
    12. ^
    13.  
    14. In file included from ../../gridb/test/tests.h:8:0,
    15. from moc_tests.cpp:9:
    16. ../../gridb/src/coord.h: In copy constructor 'Coord::Coord(const Coord&)':
    17. ../../gridb/src/coord.h:34:9: warning: base class 'class Located' should be explicitly initialized in the copy constructor [-Wextra]
    18. Coord(const Coord& loc) : Movable(loc) {}
    19. ^
    20.  
    21.  
    22. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::locationChanged(AbstractLocated const&)'
    23. collect2: error: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 
    Last edited by amreo; 19th November 2015 at 21:20. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Warning and error

    You forgot to post the errors and warnings.
    You also did not move the QObject inheritance to be the first as suggested in the other thread.
    Why all the "virtual" inheritance?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: Warning and error

    Updated. I mistaked some error but I don't resolved the warnings/errors

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Warning and error

    The linker error about "AbstractMovable::locationChanged()" is because there is no implementation of the function anywhere and something is trying to use it. You are trying to use it as a Qt signal and you are assuming that the implementation will be generated for you. For moc to do that for you AbstractMovable needs to be:
    • Publicly derived from a QObject class
    • QObject must be the first base class if multiple inheritance is used
    • Have the Q_OBJECT macro
    • Be listed in the PRO file HEADERS

  5. #5
    Join Date
    Aug 2015
    Posts
    14
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: Warning and error

    I modified it but I've got the similiar errors:

    Qt Code:
    1. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::qt_metacast(char const*)'
    2. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `VTT for Movable'
    3. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `vtable for Movable'
    4. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `virtual thunk to Movable::metaObject() const'
    5. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `typeinfo for AbstractMovable'
    6. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `virtual thunk to Movable::qt_metacall(QMetaObject::Call, int, void**)'
    7. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `Movable::staticMetaObject'
    8. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::metaObject() const'
    9. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::locationChanged(AbstractLocated const&)'
    10. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `Movable::qt_metacast(char const*)'
    11. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `AbstractMovable::qt_metacall(QMetaObject::Call, int, void**)'
    12. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `typeinfo for Movable'
    13. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `vtable for AbstractMovable'
    14. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `Movable::metaObject() const'
    15. /home/amreo/src/repo/gridb/build-gridb-Desktop-Debug/test/../bin//libgridb.so: undefined reference to `Movable::qt_metacall(QMetaObject::Call, int, void**)'
    16. collect2: error: ld returned 1 exit status
    17. make[1]: *** [test] Error 1
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 2nd April 2015, 18:02
  2. Replies: 5
    Last Post: 3rd July 2014, 12:46
  3. linux libpng warning: zlib version error
    By akos.maroy in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2014, 20:31
  4. KGlobal::locale::Warning error...
    By glafauci in forum Qt-based Software
    Replies: 2
    Last Post: 19th September 2011, 08:56
  5. Error while executing a application - Gtk WARNING
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2010, 12:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.