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. Pass a Qpair value in function

Pass a Qpair value in function

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

    May i know how will i pass a QPair value in a function?

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

      Do you mean:

      @void myFunction (const QPair<int, int> &myPair)
      {
      qDebug() << myPair.first << myPair.second;
      }@

      ?

      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
      • D Offline
        D Offline
        deepakkakkeel
        wrote on last edited by
        #3

        Suppose i have
        QPair <int, int >pair;
        pair.first = 4;
        pair.second = 3;

        Now how will i call myFunction () ?
        How to pass pair to my Function?
        Will the following work/
        myFunction(pair);

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

          Yes, why wouldn't it ?

          If you have doubts write some code to test it.

          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
          • D Offline
            D Offline
            deepakkakkeel
            wrote on last edited by
            #5

            May i know how to initialize QPair with qmakePair.
            QPair <int, int >pair = qMakePair(4, 3);
            Will the above work?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on last edited by
              #6

              Look at qpair.h:

              @QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
              {
              return QPair<T1, T2>(x, y);
              }@

              This means that "qMakePair(4, 3)" is nothing but a shorthand for something like "QPair<int, int > myPair(4, 3)", which in turn does the same as:

              @QPair <int, int > myPair;
              myPair.first = 3;
              myPair.second = 4;@

              So I see no reason why it should not work. But why not try yourself?

              (there often is more than one to achieve the same thing)

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              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