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. Is it possible to return an object of type QMap from a function call? It doesn't seem to like that I'm defining the function as a type QMap.
Forum Updated to NodeBB v4.3 + New Features

Is it possible to return an object of type QMap from a function call? It doesn't seem to like that I'm defining the function as a type QMap.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmap
3 Posts 3 Posters 1.0k Views
  • 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.
  • Q Offline
    Q Offline
    QTNewbie2020
    wrote on 24 Feb 2020, 20:59 last edited by
    #1

    Hi. I'm very, very, very new to Qt. I'm modifying a huge codeset (C++ in Linux OS) and am wondering if it is possible to return an object of type QMap from a function call? It doesn't seem to like that I'm defining the function as a type QMap.

    Very simplified example:

    QMap doSomeFunction(int)
    {
    QString someStringName;
    QMap<QString, int> _someQMap;

    someStringName = "abc";
    someIntData = int + 1000;
    _someQMap.insert(someStringName, someIntData);
    return _someQMap;
    }

    void main
    {
    QMap <QString, int> _anotherQMap;

    _anotherQMap = doSomeFunction(2);
    return;
    }

    W 1 Reply Last reply 24 Feb 2020, 22:27
    0
    • D Offline
      D Offline
      David_001
      wrote on 24 Feb 2020, 21:40 last edited by David_001
      #2
      QMap<QString, int> doSomeFunction(int)
      {
      QString someStringName;
      QMap<QString, int> _someQMap;
      
      someStringName = "abc";
      someIntData = int + 1000;
      _someQMap.insert(someStringName, someIntData);
      return _someQMap;
      }
      
      void main()
      {
      QMap <QString, int> _anotherQMap;
      
      _anotherQMap = doSomeFunction(2);
      return;
      }
      

      QMap<QString, int> doSomeFunction(int) /// <= do not forget to say which kind of qmap
      {

      }

      1 Reply Last reply
      4
      • Q QTNewbie2020
        24 Feb 2020, 20:59

        Hi. I'm very, very, very new to Qt. I'm modifying a huge codeset (C++ in Linux OS) and am wondering if it is possible to return an object of type QMap from a function call? It doesn't seem to like that I'm defining the function as a type QMap.

        Very simplified example:

        QMap doSomeFunction(int)
        {
        QString someStringName;
        QMap<QString, int> _someQMap;

        someStringName = "abc";
        someIntData = int + 1000;
        _someQMap.insert(someStringName, someIntData);
        return _someQMap;
        }

        void main
        {
        QMap <QString, int> _anotherQMap;

        _anotherQMap = doSomeFunction(2);
        return;
        }

        W Offline
        W Offline
        wrosecrans
        wrote on 24 Feb 2020, 22:27 last edited by
        #3

        @QTNewbie2020 QMap isn't, by itself, a complete type. A function can't return a QMap in-general. QMap<QString, int> is what you declare inside the function, so you have to declare the function as return that specific type of QMap to have a complete type. A QMap<float, int> for example would be a completely different type as far a sthe compiler is concerned. They just look like similar names to a human.

        1 Reply Last reply
        2

        1/3

        24 Feb 2020, 20:59

        • Login

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