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. [solved] QHash's insert() wrong use? --> VS-Debugger showed botch data due to missing Qt-Addon for VS

[solved] QHash's insert() wrong use? --> VS-Debugger showed botch data due to missing Qt-Addon for VS

Scheduled Pinned Locked Moved General and Desktop
45 Posts 7 Posters 18.0k 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.
  • H Offline
    H Offline
    huckfinn
    wrote on last edited by
    #31

    and here you have the log of my myDataController from the Watch window:

    @- myDataController {myQHash={...} } DataController

    • myQHash {d=0x003d35a0 e=0x003d35a0 } QHash<int,DataItem *>
    • d 0x003d35a0 {fakeNext=0x00000000 buckets=0x003d35d8 ref={...} ...} QHashData *
    • fakeNext 0x00000000 {next=??? h=??? } QHashData::Node *
    • buckets 0x003d35d8 QHashData::Node * *
    • ref {_q_value=1 } QBasicAtomicInt
      size 2 int
      nodeSize 12 int
      userNumBits 4 short
      numBits 4 short
      numBuckets 17 int
      sharable 1 unsigned int
    • e 0x003d35a0 {next=0x00000000 h=4011480 key=4011480 ...} QHashNode<int,DataItem *> *
    • next 0x00000000 {next=??? h=??? key=??? ...} QHashNode<int,DataItem *> *
      next CXX0030: Error: expression cannot be evaluated
      h CXX0030: Error: expression cannot be evaluated
      key CXX0030: Error: expression cannot be evaluated
      value CXX0030: Error: expression cannot be evaluated
      h 4011480 unsigned int
      key 4011480 int
    • value 0x00000001 {dataID=??? dataName={...} dataCat=??? ...} DataItem *
      dataID CXX0030: Error: expression cannot be evaluated
    • dataName {d=??? } QString
      d CXX0017: Error: symbol "" not found
      dataCat CXX0030: Error: expression cannot be evaluated
      dataCon CXX0030: Error: expression cannot be evaluated
      @
    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #32

      That log does not say much, at least not to me.
      What is the problem now? I.e. what does the program do, and what did you expect it do?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #33

        Indeed. I suggest writing unit tests for your classes.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • H Offline
          H Offline
          huckfinn
          wrote on last edited by
          #34

          Ah ok, let me make this clear:

          I have a in form of --> QHash<qint32, DataItem*>
          DataItem has a few simple attributes int, QString see class.

          Then I push key-value pairs on that QHash
          @myDataController->addNew(2512, "Work", 20482, 1272963);@
          by generating a new DataItemObject by those parameters and store
          <2512, DataItemGeneratedFrom_2512_Work_20482_1272963>

          Then my DataController, which contains my QHash, should store these values in there. As in the example above following values shoule be (2512, "Work", 20482, 1272963), but according to my WatchWindow in debug mode, there are other (not the one I entered above) values in there (see first post and picture in second post).

          1 Reply Last reply
          0
          • H Offline
            H Offline
            huckfinn
            wrote on last edited by
            #35

            [quote author="ZapB" date="1309869796"]Indeed. I suggest writing unit tests for your classes.[/quote]

            I have never done this before. VS --> Test --> New test... --> Create new
            then I shall insert test logic: @ [TestMethod]
            void TestMethod1()
            {
            //
            // TODO: Add test logic here
            //
            };@

            Any tutorials? Hints? Todos?

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #36

              Hmmm, I am not sure of how to do it with Visual Studio. I use the QtTest framework that ships with Qt. With that you create a sub-project that gets compiled as an application that tests your particular class (you have to write the tests of course). Take a look at the "docs":http://developer.qt.nokia.com/doc/qt-4.7/qtestlib-manual.html#id-df520d0c-f4d5-40a0-a379-b016eb2962a1 for an introduction to QtTest and also a "turorial":http://developer.qt.nokia.com/doc/qt-4.7/qtestlib-tutorial.html#id-286e4ba0-d890-4d30-bb60-4e3e70f88401

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • L Offline
                L Offline
                ludde
                wrote on last edited by
                #37

                Unit testing is great, but perhaps learning how to write unit tests for just this problem is a bit of an obstacle.
                I would suggest adding some debug output to your code that shows the contents of the hash table.

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #38

                  Yes unit testing is a bind and extra work but it pays dividends as your unit tests can be used to catch regressions much more easily than your production code (assuming your tests are sufficient and hat you actually run them of course).

                  Striking the balance is up to the author.

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    huckfinn
                    wrote on last edited by
                    #39

                    [quote author="ZapB" date="1309872749"]Yes unit testing is a bind and extra work but it pays dividends...[/quote]

                    Yes this is an issue, I am willing to learn. But not yet. I would be appreciated if anybody can recommend an effective Turtorial or Book regarding Test units with C++ / Qt.

                    Back to my problem. Seem to be solved!
                    I work with Visual Studio, but without the Qt-addon. SO I 've heard that VS's Debugger somtimes can not interpret Qt typical objects. In real, everything seem be alright, but the debugger shows botched data.

                    I inserted a
                    @
                    const DataItem * DataController::getDataItem(qint32 key) const
                    {
                    const DataItem * tR = NULL;
                    QHash<qint32, DataItem>::const_iterator itf = this->myQHash.find(key);
                    if(itf != maQHash.end()) tR = &itf.value();
                    return tR;
                    }
                    @
                    I checked myDataController s entries:
                    @
                    myDataController.addNew(2511, tr("Heim"), 20481);
                    myDataController.addNew(2512, tr("Work"), 20482);
                    const DataItem *tP1 = myDataController.getDataItem(2511);
                    const DataItem *tP2 = myDataController.getDataItem(2512);
                    @
                    every values in tP1 and tP2 are interpreted correctly.
                    So there was much ado about nothing?

                    Is it recommended to install the Qt-addon for VS?

                    However, I like to thank everyone for your patience.

                    Cheers Huck

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #40

                      Yes or use Qt-creator for Qt projects instead of MS Visual Studio. I switched and am very glad that I did.

                      There is not much to unit tests beyond what is covered in the docs I linked above. They just take time to write - often just as long as the class under test if you cover everything.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        ludde
                        wrote on last edited by
                        #41

                        Glad to hear it worked out in the end!
                        If you really want to use Visual Studio as your IDE, I would definitely recommend installing the Qt Visual Studio Addin. But then, I cannot really see any good reason for using Visual Studio for Qt development at all. Qt Creator is IMO a much nicer IDE in pretty much every aspect, even for pure C++ development without Qt. But that's (at least partly) a matter of taste, I guess.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on last edited by
                          #42

                          [quote author="huckfinn" date="1309876721"]
                          Back to my problem. Seem to be solved!
                          I work with Visual Studio, but without the Qt-addon. SO I 've heard that VS's Debugger somtimes can not interpret Qt typical objects. In real, everything seem be alright, but the debugger shows botched data.
                          [/quote]

                          This add on also adds some additional info to the debugger file autoexp.dat which is used by the debugger to exand classes ti user readable stuff. If those additions are missing, it is hard to read Qt classes...

                          Nokia Certified Qt Specialist.
                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            huckfinn
                            wrote on last edited by
                            #43

                            [quote author="ZapB" date="1309876995"]Yes or use Qt-creator for Qt projects instead of MS Visual Studio.[/quote]

                            I use onyl QtCreator, when developing at home. At work, I also would like to develop with Qt Creator, but the Projects are for VS as they told me.

                            It is a big project; which I had to generate with cmake2.8.
                            In cmake I only could select VS 6, 7, 8, 9 etc. Eclipse CDT, CodeBlocks, and some other IDEs etc.
                            But no QT :(

                            If there is a way to export that project for Qt, please let me know. Thank you!

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              huckfinn
                              wrote on last edited by
                              #44

                              [quote author="ludde" date="1309877294"]Qt Creator is IMO a much nicer IDE in pretty much every aspect[/quote]
                              FULL ACK!

                              1 Reply Last reply
                              0
                              • Z Offline
                                Z Offline
                                ZapB
                                wrote on last edited by
                                #45

                                Qt-creator has cmake project support. From memory just open qt-creator then go to File->Open File or Project and choose the CMakeLists.txt. You will then be asked by the import wizard to choose a build location etc. Qt-creator will then run cmake for you and populate the project tree etc. Give it a try and see how you get on.

                                Nokia Certified Qt Specialist
                                Interested in hearing about Qt related work

                                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