Solved Very newbie question - delete object
-
Sorry for the very basic question... but I'm at my 3rd day at this and I can't find why this is breaking this up... In Visual Studio 2019 latest update (16.10.2) with Qt latest update (5.12.11) installed from Offline Installer for VC2017, this works fine:
int main(int argc, char **argv) { QApplication app(argc, argv); QMainWindow* pmain = new QMainWindow(); delete pmain; }
while this throws an exception on the delete:
int main(int argc, char **argv) { QApplication app(argc, argv); QMainWindow* pmain = new QMainWindow(); pmain->setObjectName(QString("Yep")); delete pmain; }
any method that I call with numbers and other objects work fine, but it seems that any method call with QString makes the delete on the object to fail with an unnamed exception. Meanwhile QString by itself work fine, for example this has no problems:
int main(int argc, char **argv) { QApplication app(argc, argv); QMainWindow* pmain = new QMainWindow(); QString * pstr = new QString("Yep"); delete pstr; delete pmain; }
Maybe there's some hidden setting somewhere on how QObjects handle QStrings? Any suggestion is appreciated.
-
Ah... it was one of those things... when you stop overthinking it the solution suddenly comes up.
I was linking the release Qt5Widgets (Qt5Widgets.lib) with a debug CRT, and that was throwing the problem. Once I changed that to the debug one (Qt5Widgetsd.lib) the problem went away.
I guess can't mix those up. Sorry the trouble, problem is resolved.