跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  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
Forum Updated to NodeBB v4.3 + New Features

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

已排程 已置頂 已鎖定 已移動 General and Desktop
45 貼文 7 Posters 21.5k 瀏覽 1 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • H 離線
    H 離線
    huckfinn
    寫於 2011年7月5日 上午8:55 最後由 編輯
    #21

    ah ok. without MyDockWidget:: in front?

    just:
    @int main(int p_argsc, char *p_argsv[] ) {
    myDataController.addNew(2511, "Heim", 20481, 1272923);
    myDataController.addNew(2512, "Work", 20482, 1272963);
    // Breakpoint here
    return 1;
    }
    @

    1 條回覆 最後回覆
    0
    • L 離線
      L 離線
      ludde
      寫於 2011年7月5日 上午9:00 最後由 編輯
      #22

      Yeah, but then you cannot use myDataController, you have to create it first.
      And remove the declaration of main() in the .h file.

      1 條回覆 最後回覆
      0
      • H 離線
        H 離線
        huckfinn
        寫於 2011年7月5日 上午10:05 最後由 編輯
        #23

        [quote author="ludde" date="1309856111"]Regarding the link errors, which IDE are you using to build your project?[/quote]
        Visual Studio 2008 Version 9

        1 條回覆 最後回覆
        0
        • H 離線
          H 離線
          huckfinn
          寫於 2011年7月5日 上午10:14 最後由 編輯
          #24

          [quote author="ludde" date="1309856111"]The main function is inside the MyDockWidget class - looks really weird to me... Does the main function not have to be global?[/quote]

          This project is in real a *.dll. I just extracted the required methods and classes to reproduce my QHash problem.

          Hint: The original projects were generated by cmake, which should add corresponding libs correctly.

          1 條回覆 最後回覆
          0
          • G 離線
            G 離線
            giesbert
            寫於 2011年7月5日 上午10:57 最後由 編輯
            #25

            huckfinn,

            are you using MSDEV for building?
            If yes, please post your vcproj file via pastebin ort similar shares. I'm sure, the problem is located there.

            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 條回覆 最後回覆
            0
            • H 離線
              H 離線
              huckfinn
              寫於 2011年7月5日 上午11:09 最後由 編輯
              #26

              Here is my vproj file:

              @
              <?xml version="1.0" encoding="Windows-1252"?>
              <VisualStudioProject
              ProjectType="Visual C++"
              Version="9,00"
              Name="deldel3"
              ProjectGUID="{19DD986F-AEBE-4C05-8309-B174DE1C1C3F}"
              RootNamespace="deldel3"
              TargetFrameworkVersion="196613"

              <Platforms>
              <Platform
              Name="Win32"
              />
              </Platforms>
              <ToolFiles>
              </ToolFiles>
              <Configurations>
              <Configuration
              Name="Debug|Win32"
              OutputDirectory="$(SolutionDir)$(ConfigurationName)"
              IntermediateDirectory="$(ConfigurationName)"
              ConfigurationType="1"
              UseOfMFC="0"
              CharacterSet="2"

              <Tool
              Name="VCPreBuildEventTool"
              />
              <Tool
              Name="VCCustomBuildTool"
              />
              <Tool
              Name="VCXMLDataGeneratorTool"
              />
              <Tool
              Name="VCWebServiceProxyGeneratorTool"
              />
              <Tool
              Name="VCMIDLTool"
              />
              <Tool
              Name="VCCLCompilerTool"
              Optimization="0"
              AdditionalIncludeDirectories=""C:\\Qt\\qt-win-opensource-src-4.5.0\\include\\QtGui";"C:\\Qt\\qt-win-opensource-src-4.5.0\\include\\QtCore";"C:\\Qt\\qt-win-opensource-src-4.5.0\\include""
              MinimalRebuild="true"
              BasicRuntimeChecks="3"
              RuntimeLibrary="2"
              WarningLevel="3"
              DebugInformationFormat="4"
              />
              <Tool
              Name="VCManagedResourceCompilerTool"
              />
              <Tool
              Name="VCResourceCompilerTool"
              />
              <Tool
              Name="VCPreLinkEventTool"
              />
              <Tool
              Name="VCLinkerTool"
              LinkLibraryDependencies="false"
              UseUnicodeResponseFiles="false"
              AdditionalLibraryDirectories=""C:\\Qt\\qt-win-opensource-src-4.5.0\\lib\\QtCored4.lib";"C:\\Qt\\qt-win-opensource-src-4.5.0\\lib\\QtCore4.lib""
              GenerateDebugInformation="true"
              EntryPointSymbol="main"
              TargetMachine="1"
              />
              <Tool
              Name="VCALinkTool"
              />
              <Tool
              Name="VCManifestTool"
              />
              <Tool
              Name="VCXDCMakeTool"
              />
              <Tool
              Name="VCBscMakeTool"
              />
              <Tool
              Name="VCFxCopTool"
              />
              <Tool
              Name="VCAppVerifierTool"
              />
              <Tool
              Name="VCPostBuildEventTool"
              />
              </Configuration>
              <Configuration
              Name="Release|Win32"
              OutputDirectory="$(SolutionDir)$(ConfigurationName)"
              IntermediateDirectory="$(ConfigurationName)"
              ConfigurationType="1"
              CharacterSet="2"
              WholeProgramOptimization="1"

              <Tool
              Name="VCPreBuildEventTool"
              />
              <Tool
              Name="VCCustomBuildTool"
              />
              <Tool
              Name="VCXMLDataGeneratorTool"
              />
              <Tool
              Name="VCWebServiceProxyGeneratorTool"
              />
              <Tool
              Name="VCMIDLTool"
              />
              <Tool
              Name="VCCLCompilerTool"
              Optimization="2"
              EnableIntrinsicFunctions="true"
              RuntimeLibrary="2"
              EnableFunctionLevelLinking="true"
              WarningLevel="3"
              DebugInformationFormat="3"
              />
              <Tool
              Name="VCManagedResourceCompilerTool"
              />
              <Tool
              Name="VCResourceCompilerTool"
              />
              <Tool
              Name="VCPreLinkEventTool"
              />
              <Tool
              Name="VCLinkerTool"
              GenerateDebugInformation="true"
              OptimizeReferences="2"
              EnableCOMDATFolding="2"
              TargetMachine="1"
              />
              <Tool
              Name="VCALinkTool"
              />
              <Tool
              Name="VCManifestTool"
              />
              <Tool
              Name="VCXDCMakeTool"
              />
              <Tool
              Name="VCBscMakeTool"
              />
              <Tool
              Name="VCFxCopTool"
              />
              <Tool
              Name="VCAppVerifierTool"
              />
              <Tool
              Name="VCPostBuildEventTool"
              />
              </Configuration>
              </Configurations>
              <References>
              </References>
              <Files>
              <Filter
              Name="Source Files"
              Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
              UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"

              <File
              RelativePath=".\\DataController.cpp"
              >
              </File>
              <File
              RelativePath=".\\DataItem.cpp"
              >
              </File>
              <File
              RelativePath=".\\MyDockWidget.cpp"
              >
              </File>
              </Filter>
              <Filter
              Name="Header Files"
              Filter="h;hpp;hxx;hm;inl;inc;xsd"
              UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"

              <File
              RelativePath=".\\DataController.h"
              >
              </File>
              <File
              RelativePath=".\\DataItem.h"
              >
              </File>
              <File
              RelativePath=".\\MyDockWidget.h"
              >
              </File>
              </Filter>
              <Filter
              Name="Resource Files"
              Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
              UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"

              </Filter>
              </Files>
              <Globals>
              </Globals>
              </VisualStudioProject>
              @

              Thank you for your patience. Cheers Huck

              [EDIT: code formatting, use @-tags, not 'quote', Volker]

              1 條回覆 最後回覆
              0
              • G 離線
                G 離線
                giesbert
                寫於 2011年7月5日 上午11:30 最後由 編輯
                #27

                Hi,

                I see two bugs in there:

                you do not link the QtCore.lib in release mode

                You link debug and release lib in debug mode.

                Correct this and try again please.

                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 條回覆 最後回覆
                0
                • G 離線
                  G 離線
                  giesbert
                  寫於 2011年7月5日 上午11:31 最後由 編輯
                  #28

                  additionally, you would typically have some stuff in the Globals section:

                  @
                  <Globals>
                  <Global
                  Name="MocDir"
                  Value=".\\GeneratedFiles\\$(ConfigurationName)"
                  />
                  <Global
                  Name="QtVersion"
                  Value="MSVS2008SP1"
                  />
                  <Global
                  Name="RccDir"
                  Value=".\\GeneratedFiles"
                  />
                  <Global
                  Name="UicDir"
                  Value=".\\GeneratedFiles"
                  />
                  </Globals>
                  </VisualStudioProject>
                  @

                  EDIT: this is used by the Qt plugin for MSVS

                  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 條回覆 最後回覆
                  0
                  • H 離線
                    H 離線
                    huckfinn
                    寫於 2011年7月5日 上午11:38 最後由 編輯
                    #29

                    They're empty..
                    @ <Globals>
                    </Globals>@

                    What was MSDEV? (previous post)

                    1 條回覆 最後回覆
                    0
                    • H 離線
                      H 離線
                      huckfinn
                      寫於 2011年7月5日 上午11:50 最後由 編輯
                      #30

                      [quote author="Gerolf" date="1309865412"]Hi, I see two bugs in there: # you do not link the QtCore.lib in release mode # You link debug and release lib in debug mode. Correct this and try again please.[/quote]

                      Thank you Gerolf. Now, I can compile link and run my program.
                      Project --> Properties --> Linker --> Input --> Additional dependecies --> PathToCore4Lib\QtCore4.lib

                      And I have same error with my QHash. It was reproducable.

                      Here is my sourcecode again:
                      MyDockWidget cpp and h
                      @
                      #include "MyDockWidget.h"
                      #include "DataController.h"

                      MyDockWidget::MyDockWidget( )
                      {
                      }

                      int main(int p_argsc, char *p_argsv[] )
                      {
                      DataController myDataController;
                      myDataController.addNew(2511, "Heim", 20481, 1272923);
                      myDataController.addNew(2512, "Work", 20482, 1272963);
                      // Breakpoint here
                      return 1;
                      }

                      // here header
                      #ifndef MY_DOCK_WIDGET_H
                      #define My_DOCK_WIDGET_H
                      #include <QString>
                      #include "DataController.h"

                      class MyDockWidget
                      {
                      public:
                      MyDockWidget();
                      DataController myDataController;
                      };
                      #endif // MY_DOCK_WIDGET_H
                      @

                      DataController cpp and h
                      @
                      #include <QHash>
                      #include "DataController.h"
                      #include "DataItem.h"

                      void DataController::addNew(qint32 tID, QString tName, qint32 tCat, qint32 tCon)
                      {
                      DataItem * tPI = new DataItem(tID, tName, tCat, tCon);
                      this->myQHash.insert(tID, tPI);
                      }

                      DataController::~DataController(void) {}

                      // here header
                      #pragma once

                      #include <QString>
                      #include <QHash>
                      #include "DataItem.h"

                      class DataController
                      {
                      public:
                      ~DataController(void);
                      void addNew(qint32, QString, qint32, qint32);
                      private:
                      QHash<qint32, DataItem*> myQHash;
                      };
                      @

                      DataItem cpp and h
                      @
                      #include "DataItem.h"
                      #include <QString>
                      DataItem::DataItem()
                      {
                      this->dataID = 0;
                      this->dataCon = 0;
                      this->dataCat = 0;
                      this->dataName = "defName";
                      }

                      DataItem::DataItem(qint32 tId, QString tName, qint32 tCat, qint32 tCon)
                      {
                      this->dataID = tId;
                      this->dataCon = tCon;
                      this->dataCat = tCat;
                      this->dataName = tName;
                      }

                      qint32 DataItem::getID() const { return this->dataID; }

                      QString DataItem::getName() const { return this->dataName; }

                      qint32 DataItem::getCat() const { return this->dataCat; }

                      qint32 DataItem::getCon() const { return this->dataCon; }

                      DataItem::~DataItem(void) {}

                      // here header
                      #pragma once

                      #include <QString>

                      class DataItem
                      {
                      public:
                      DataItem();
                      DataItem(qint32 tId, QString tName, qint32 tCat, qint32 tCon);
                      ~DataItem(void);

                      qint32 getID() const;
                      QString getName() const;
                      qint32 getCat() const;
                      qint32 getCon() const;

                      private:
                      qint32 dataID;
                      QString dataName;
                      qint32 dataCat;
                      qint32 dataCon;
                      };
                      @

                      Cheers Huck

                      1 條回覆 最後回覆
                      0
                      • H 離線
                        H 離線
                        huckfinn
                        寫於 2011年7月5日 上午11:57 最後由 編輯
                        #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 條回覆 最後回覆
                        0
                        • L 離線
                          L 離線
                          ludde
                          寫於 2011年7月5日 下午12:37 最後由 編輯
                          #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 條回覆 最後回覆
                          0
                          • Z 離線
                            Z 離線
                            ZapB
                            寫於 2011年7月5日 下午12:43 最後由 編輯
                            #33

                            Indeed. I suggest writing unit tests for your classes.

                            Nokia Certified Qt Specialist
                            Interested in hearing about Qt related work

                            1 條回覆 最後回覆
                            0
                            • H 離線
                              H 離線
                              huckfinn
                              寫於 2011年7月5日 下午12:51 最後由 編輯
                              #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 條回覆 最後回覆
                              0
                              • H 離線
                                H 離線
                                huckfinn
                                寫於 2011年7月5日 下午12:54 最後由 編輯
                                #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 條回覆 最後回覆
                                0
                                • Z 離線
                                  Z 離線
                                  ZapB
                                  寫於 2011年7月5日 下午12:59 最後由 編輯
                                  #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 條回覆 最後回覆
                                  0
                                  • L 離線
                                    L 離線
                                    ludde
                                    寫於 2011年7月5日 下午1:03 最後由 編輯
                                    #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 條回覆 最後回覆
                                    0
                                    • Z 離線
                                      Z 離線
                                      ZapB
                                      寫於 2011年7月5日 下午1:32 最後由 編輯
                                      #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 條回覆 最後回覆
                                      0
                                      • H 離線
                                        H 離線
                                        huckfinn
                                        寫於 2011年7月5日 下午2:38 最後由 編輯
                                        #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 條回覆 最後回覆
                                        0
                                        • Z 離線
                                          Z 離線
                                          ZapB
                                          寫於 2011年7月5日 下午2:43 最後由 編輯
                                          #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 條回覆 最後回覆
                                          0

                                          30/45

                                          2011年7月5日 上午11:50

                                          • 登入

                                          • Login or register to search.
                                          30 / 45
                                          • 第一個貼文
                                            30/45
                                            最後的貼文
                                          0
                                          • 版面
                                          • 最新
                                          • 標籤
                                          • 熱門
                                          • 使用者
                                          • 群組
                                          • 搜尋
                                          • Get Qt Extensions
                                          • Unsolved