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. Can't understand return type of qBinaryFind();
QtWS25 Last Chance

Can't understand return type of qBinaryFind();

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 921 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    I read all documentation which concerning this function(all 3 variations), and still can't get why developers did'nt make as return type just vector of ints... I tried as at example, and it gives an error:

    0_1541783243991_qfind.jpg

    P.S. tried to set return value to *uchar as compiler asks, it always return 253 in any case. Confused.

    1 Reply Last reply
    0
    • mranger90M Offline
      mranger90M Offline
      mranger90
      wrote on last edited by
      #2

      I'm guessing that tempByte is a QVector<uchar>. if that is the case then the iterator must be of type QVector<uchar>, not QVector<int>

      EngelardE 1 Reply Last reply
      7
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        In addition to @mranger90, as suggested in the current documentation, you should use std::binary_search or std::lower_bound instead.

        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
        2
        • mranger90M mranger90

          I'm guessing that tempByte is a QVector<uchar>. if that is the case then the iterator must be of type QVector<uchar>, not QVector<int>

          EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by Engelard
          #4

          @mranger90 Thanks! Did'nt notice such a small mistake.

          @SGaist oh.. but why they went obsolete? What's wrong with those functions?

          P.S. still can't understand the point of iterator type, why dont use simple int instead?

          jsulmJ 1 Reply Last reply
          0
          • EngelardE Engelard

            @mranger90 Thanks! Did'nt notice such a small mistake.

            @SGaist oh.. but why they went obsolete? What's wrong with those functions?

            P.S. still can't understand the point of iterator type, why dont use simple int instead?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Engelard said in Can't understand return type of qBinaryFind();:

            P.S. still can't understand the point of iterator type, why dont use simple int instead?

            Because you can use the iterator as parameter to any other function which expects an iterator.

            I guess these functions are deprecated because the standard C++ library now provides same functionality.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              @jsulm's guess is correct. The goal of Qt is not to duplicate the STD. Since the original functions provided by Qt have been integrated in the STD, there's no reason to keep them hence they are now considered obsolete.

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

              EngelardE 1 Reply Last reply
              0
              • SGaistS SGaist

                @jsulm's guess is correct. The goal of Qt is not to duplicate the STD. Since the original functions provided by Qt have been integrated in the STD, there's no reason to keep them hence they are now considered obsolete.

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by
                #7

                @SGaist why then exists stuff like QVectors? they are also the same.

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

                  No they are not, Qt's containers are implicitly shared which is not the case of the STD containers.

                  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
                  1

                  • Login

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