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 I do this?
QtWS25 Last Chance

Can I do this?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.1k 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.
  • I Offline
    I Offline
    I-sty
    wrote on last edited by
    #1

    @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
    0
    • W Offline
      W Offline
      Wilk
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • I Offline
        I Offline
        I-sty
        wrote on last edited by
        #3

        [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
        0
        • W Offline
          W Offline
          Wilk
          wrote on last edited by
          #4

          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
          0
          • I Offline
            I Offline
            I-sty
            wrote on last edited by
            #5

            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
            0
            • ZlatomirZ Offline
              ZlatomirZ Offline
              Zlatomir
              wrote on last edited by
              #6

              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
              0
              • M Offline
                M Offline
                moritzg
                wrote on last edited by
                #7

                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
                0
                • W Offline
                  W Offline
                  Wilk
                  wrote on last edited by
                  #8

                  @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
                  0

                  • Login

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