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] QMap and QVector2D not compatible
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QMap and QVector2D not compatible

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.9k 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.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hi,

    Is there any way how to implement operator < for QVector2D?
    QMap using operator < to check keys.

    @C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore\qmap.h:67: error: C2678: binary '<' : no operator found which takes a left-hand operand of type 'const QVector2D' (or there is no acceptable conversion)
    c:\qt\qt5.4.0\5.4\msvc2013_64_opengl\include\qtcore\qelapsedtimer.h(80): or 'bool operator <(const QElapsedTimer &,const QElapsedTimer &) throw()'
    c:\qt\qt5.4.0\5.4\msvc2013_64_opengl\include\qtcore\qcollator.h(72): or 'bool operator <(const QCollatorSortKey &,const QCollatorSortKey &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(1424): or 'bool operator <(const QStringRef &,const QStringRef &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(1117): or 'bool operator <(const char *,QLatin1String)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(1060): or 'bool operator <(QLatin1String,QLatin1String)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(652): or 'bool operator <(const char *,const QStringRef &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(645): or 'bool operator <(const char *,const QString &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qstring.h(585): or 'bool operator <(const QString &,const QString &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qbytearray.h(572): or 'bool operator <(const char *,const QByteArray &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qbytearray.h(570): or 'bool operator <(const QByteArray &,const char *)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qbytearray.h(568): or 'bool operator <(const QByteArray &,const QByteArray &)'
    C:\Qt\Qt5.4.0\5.4\msvc2013_64_opengl\include\QtCore/qchar.h(539): or 'bool operator <(QChar,QChar)'
    while trying to match the argument list '(const QVector2D, const QVector2D)'@

    I use QMap this way:
    QMap<QVector2D, float> for Undo action in heightmap editing.
    QVector2D - position
    float - height

    I sort QList values per key and choose first one, other just throw. I used QList and with every edit check if position is already edited, but it was very slow and now trying to figure out fast performance for this action. But seems QMap bit complicate it :/

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Rather than QList, you can use QVector which might be faster.

      As for your original problem you would have to provide your implementation of

      @bool operator<(const QVector2D &v1, const QVector2D &v2)@

      in order to work with QMap

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glararan
        wrote on last edited by
        #3

        Yes but this implementation should be inside of QVector2D or in QMap? And do I need edit source code or can I write it in some header file like QDataStream operators <<, >>?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          No, it doesn't need to.

          Put it where you are using your QMap

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            glararan
            wrote on last edited by
            #5

            Nice, works

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Good, then please update the thread title prepending [solved] so other forum users may know a solution has been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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