Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Can't understand return type of qBinaryFind();

    General and Desktop
    4
    8
    588
    Loading More Posts
    • 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.
    • Engelard
      Engelard last edited by Engelard

      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 Reply Quote 0
      • mranger90
        mranger90 last edited by

        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>

        Engelard 1 Reply Last reply Reply Quote 7
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 2
          • Engelard
            Engelard @mranger90 last edited by 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?

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @Engelard last edited by

              @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 Reply Quote 3
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                @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

                Engelard 1 Reply Last reply Reply Quote 0
                • Engelard
                  Engelard @SGaist last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by SGaist

                    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 Reply Quote 1
                    • First post
                      Last post