Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Can I do this?

    General and Desktop
    4
    8
    2719
    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.
    • I
      I-sty last edited by

      @extern QVector <theList, QMap <QString, short, short > > actualList;@

      Where:
      theList is a class from me;
      actualList the vector name

      Sorry, for my bad English. My first language is Hungarian.

      1 Reply Last reply Reply Quote 0
      • W
        Wilk last edited by

        Hello.
        AFAIK you code is absolutely wrong. What do you want to achieve?

        1 Reply Last reply Reply Quote 0
        • I
          I-sty last edited by

          [quote author="Wilk" date="1342978778"]Hello.
          AFAIK you code is absolutely wrong. What do you want to achieve?[/quote]

          Yes I known.
          Again. I have a class ("theList") with 3 parts (QString, short, short).
          I have a vector "actualList". And I want a binarySearch what returns a position. But what I wrote "didn't work":http://qt-project.org/forums/viewthread/18954/ . And I thought that I have added the "QMap":http://doc.qt.nokia.com/4.7-snapshot/qmap.html class because it has a searching part.

          Sorry, for my bad English. My first language is Hungarian.

          1 Reply Last reply Reply Quote 0
          • W
            Wilk last edited by

            Oh my god.

            Implement operator< for your theList

            Use QSet or std::set: these classes provide some kinds of search functions. But they don't allow you to change key. If you need it then you'll have to delete an object from container, change key and insert it again.

            1 Reply Last reply Reply Quote 0
            • I
              I-sty last edited by

              Please read "my previous post":http://qt-project.org/forums/viewthread/18954/ . :) Thanks.
              This is my main problem.

              Sorry, for my bad English. My first language is Hungarian.

              1 Reply Last reply Reply Quote 0
              • Zlatomir
                Zlatomir last edited by

                QVector has one template parameter as the data-type that goes into the vector, so the answer is no, you can't do that code, and i don't understand what kind of data structure have you tried to create there.

                You can just use a "QMap":http://qt-project.org/doc/qt-4.8/qmap.html#details <short, theList> where the key (the first template parameter) is your procID and the second is the actual instance with that id.

                //Wilk, he doesn't need operator< if he passes a compare function/functor to the binary search

                https://forum.qt.io/category/41/romanian

                1 Reply Last reply Reply Quote 0
                • M
                  moritzg last edited by

                  if you want a list of <QString, short, short>, try using a std::list - or QList ;) - of std::tuple's. Something like

                  @ std::list< std::tuple<QString,short,short> > myList; @

                  Note that the whitespace between the two ">" is significant, because otherwise your compiler will probably complain about invalid use of operator>>. Also, std::tuple is C++0x, so you may need to update your headers accordingly.

                  You can then declare this list as extern in your various files and use it as you normally would, as long as the list is defined before any of the externs are actually called at runtime.

                  1 Reply Last reply Reply Quote 0
                  • W
                    Wilk last edited by

                    @Zlatomir
                    AFAIK operator< is needed for std::set and QSet, because at least in std::set elements are are stored in an orderly. And search inside std::set and in QSet is actually a binary search, at least in GCC implementation of std::set RB-tree is used. This approach may be a little bit slower but is easy to implement.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post