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. Initialize QMap with stream operators?

Initialize QMap with stream operators?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 4.0k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    QMap doesn't seem to have a stream operator defined for easy initialization, like so:

    @
    template <class Key, class T>
    QMap<Key, T>& operator<<(QMap<Key, T>& map,
    const QPair<Key, T>& data)
    {
    map.insert(data.first, data.second);
    return map;
    }

    // Use:
    static const QMap<int, QString> someMap =
    QMap<int, QString>() << qMakePair(1, QString("One"))
    << qMakePair(2, QString("Two"));
    @

    Is there a good reason no such operator is defined in Qt?

    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