[solved] QHash's insert() wrong use? --> VS-Debugger showed botch data due to missing Qt-Addon for VS
-
wrote on 4 Jul 2011, 13:02 last edited by
Have you unit tested you SpecialObject class to ensure that it works properly for common operations (e.g. creation, destruction, assignment, copying, output)?
Can you post the code for SpecialObject please?
-
wrote on 4 Jul 2011, 13:04 last edited by
I think you will have to show us the SpecialObject class, if you cannot figure out what's wrong with it from the help you've been given so far.
-
wrote on 4 Jul 2011, 13:06 last edited by
Even better, create a complete test case, consisting of just the class, a main method and a method that triggers the crash.
-
wrote on 5 Jul 2011, 08:19 last edited by
Here you have compileable but not yet linkable codes. LinkError see bottom.
DataItem.cpp
@#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) {}@
DataItem.h
@#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;
};@DataController.cpp
@#include <QHash>
#include "DataController.h"
#include "DataItem.h"//DataController::DataController(void)
//{
//
//}//void DataController::addNew(DataItem * tPI) { this->myQHash.insert(tPI->getID(), *tPI); }
void DataController::addNew(qint32 tID, QString tName, qint32 tCat, qint32 tCon)
{
//DataItem tPI (tID, tName, tCat, tCon);
DataItem * tPI = new DataItem(tID, tName, tCat, tCon);
this->myQHash.insert(tID, tPI);
}DataController::~DataController(void) {}@
DataController.h
@
#pragma once#include <QString>
#include <QHash>
#include "DataItem.h"class DataController
{
public:
//DataController(void);
~DataController(void);
//void addNew(DataItem * tPI);
void addNew(qint32, QString, qint32, qint32);private:
QHash<qint32, DataItem*> myQHash;
};@MyDockWidget.cpp
@#include "MyDockWidget.h"
#include "DataController.h"
#include <QString>
MyDockWidget::MyDockWidget( )
{
//DataController myDataController;
}int MyDockWidget::main(int p_argsc, char *p_argsv[] )
{
//this->myDataController = new DataController();
myDataController.addNew(2511, "Heim", 20481, 1272923);
myDataController.addNew(2512, "Work", 20482, 1272963);
// Breakpoint herereturn 1;
}
@MyDockWidget.h
@#ifndef MY_DOCK_WIDGET_H
#define My_DOCK_WIDGET_H
#include <QString>
#include "DataController.h"class MyDockWidget
{
//Q_OBJECTpublic: /// @brief constructor MyDockWidget(); DataController myDataController;
int main( int p_argsc, char *p_argsv[] );
};
#endif // MY_DOCK_WIDGET_H
@I now get a Linker-Error:
1>Linking...
1>DataItem.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (_imp??1QString@@QAE@XZ) referenced in function __unwindfunclet$??0DataItem@@QAE@XZ$0but I did not use any Libs or Dlls??! How is that be?
-
wrote on 5 Jul 2011, 08:22 last edited by
Yes you are. You are using the QtCore dll. Also where is your main() function?
-
wrote on 5 Jul 2011, 08:27 last edited by
You are missing the linker options in your pro file.
can you show it to us?
or what do you use for compiling?For me, your code compiles fine.
-
wrote on 5 Jul 2011, 08:43 last edited by
Code looks OK to me. Except your DataController destructor should probably destroy the DataItems. But the way your DataItems are now, you should be able to pass them around by value, i.e. not bother with new/delete and the use of pointers.
-
wrote on 5 Jul 2011, 08:43 last edited by
@Gerolf: Yes the compilation is not my problem ;) My linker will not link my stuff ;)
@ZapB: Ok, I included the %QTDIR%qt4.5.0libQtCore4.lib to
Project --> Properties --> Linker --> General --> Add additional Libraries. But same linker error as above.bq. 1>Linking...
1>DataItem.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (_imp??1QString@@QAE@XZ) referenced in function __unwindfunclet$??0DataItem@@QAE@XZ$0
1>DataController.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (_imp??1QString@@QAE@XZ)
////etc....
1>deldel3 - 19 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========Qstring is in QtCore as well as far as I know?
The main? Is that wrong?
-
wrote on 5 Jul 2011, 08:46 last edited by
@ludde: Yes of course. I will destroy all DataItems pointers objects which are stored in my heap after all.
But therefore I have to store them first, which was my initial problem. Now, my smaller problem is to make that app run ;) -
wrote on 5 Jul 2011, 08:51 last edited by
I could not see a main() function in what you posted.
-
wrote on 5 Jul 2011, 08:55 last edited by
The main function is inside the MyDockWidget class - looks really weird to me... Does the main function not have to be global?
Regarding the link errors, which IDE are you using to build your project?
-
wrote on 5 Jul 2011, 08:55 last edited by
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;
}
@ -
wrote on 5 Jul 2011, 09:00 last edited by
Yeah, but then you cannot use myDataController, you have to create it first.
And remove the declaration of main() in the .h file. -
wrote on 5 Jul 2011, 10:05 last edited by
[quote author="ludde" date="1309856111"]Regarding the link errors, which IDE are you using to build your project?[/quote]
Visual Studio 2008 Version 9 -
wrote on 5 Jul 2011, 10:14 last edited by
[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.
-
wrote on 5 Jul 2011, 10:57 last edited by
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. -
wrote on 5 Jul 2011, 11:09 last edited by
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]
-
wrote on 5 Jul 2011, 11:30 last edited by
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.
-
wrote on 5 Jul 2011, 11:31 last edited by
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
-
wrote on 5 Jul 2011, 11:38 last edited by
They're empty..
@ <Globals>
</Globals>@What was MSDEV? (previous post)
19/45