From e9e1168934d70d0a89609762363ea3b0f692d5f6 Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Fri, 11 Oct 2024 17:05:58 +0300 Subject: [PATCH 1/2] Fix crash when no simulator found on the first start --- qucs/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qucs/main.cpp b/qucs/main.cpp index cbaca9553..6f9da871e 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -179,7 +179,9 @@ bool saveApplSettings() qs.setItem("font", QucsSettings.font.toString()); qs.setItem("appFont", QucsSettings.appFont.toString()); qs.setItem("textFont", QucsSettings.textFont.toString()); - qs.setItem("MainWindowGeometry", QucsMain->saveGeometry()); + if (QucsMain != 0) { + qs.setItem("MainWindowGeometry", QucsMain->saveGeometry()); + } // store LargeFontSize as a string, so it will be also human-readable in the settings file (will be a @Variant() otherwise) qs.setItem("LargeFontSize", QString::number(QucsSettings.largeFontSize)); From 72acdd58b03de9a5597c017e54db431ba0498a02 Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Fri, 11 Oct 2024 17:15:02 +0300 Subject: [PATCH 2/2] Assign QucsMain to nullptr instead of 0 --- qucs/components/component.cpp | 2 +- qucs/components/spicefile.cpp | 2 +- qucs/extsimkernels/ngspice.cpp | 2 +- qucs/main.cpp | 4 ++-- qucs/schematic_file.cpp | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qucs/components/component.cpp b/qucs/components/component.cpp index c9256b2fb..627aeced1 100644 --- a/qucs/components/component.cpp +++ b/qucs/components/component.cpp @@ -1787,7 +1787,7 @@ Component *getComponentFromName(QString &Line, Schematic *p) { if (!c) { /// \todo enable user to load partial schematic, skip unknown components - if (QucsMain != 0) { + if (QucsMain != nullptr) { QMessageBox *msg = new QMessageBox(QMessageBox::Warning, QObject::tr("Warning"), QObject::tr("Format Error:\nUnknown component!\n" "%1\n\n" diff --git a/qucs/components/spicefile.cpp b/qucs/components/spicefile.cpp index 6a163b06c..ae000a462 100644 --- a/qucs/components/spicefile.cpp +++ b/qucs/components/spicefile.cpp @@ -388,7 +388,7 @@ bool SpiceFile::recreateSubNetlist(QString *SpiceFile, QString *FileName) (*filstream) << NetText; // only interact with the GUI if it was launched - if (QucsMain) { + if (QucsMain != nullptr) { QucsMain->statusBar()->showMessage(tr("Converting SPICE file \"%1\".").arg(*SpiceFile), 2000); } else diff --git a/qucs/extsimkernels/ngspice.cpp b/qucs/extsimkernels/ngspice.cpp index 2170ac2ac..c411d6ff9 100644 --- a/qucs/extsimkernels/ngspice.cpp +++ b/qucs/extsimkernels/ngspice.cpp @@ -486,7 +486,7 @@ void Ngspice::slotSimulate() QString ngsp_cmd = cmd_args.at(0); cmd_args.removeAt(0); SimProcess->start(ngsp_cmd,cmd_args); - if (QucsMain) + if (QucsMain != nullptr) emit started(); } diff --git a/qucs/main.cpp b/qucs/main.cpp index 6f9da871e..c788dec8d 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -63,7 +63,7 @@ tQucsSettings QucsSettings; -QucsApp *QucsMain = 0; // the Qucs application itself +QucsApp *QucsMain = nullptr; // the Qucs application itself QString lastDir; // to remember last directory for several dialogs QStringList qucsPathList; VersionTriplet QucsVersion; // Qucs version string @@ -179,7 +179,7 @@ bool saveApplSettings() qs.setItem("font", QucsSettings.font.toString()); qs.setItem("appFont", QucsSettings.appFont.toString()); qs.setItem("textFont", QucsSettings.textFont.toString()); - if (QucsMain != 0) { + if (QucsMain != nullptr) { qs.setItem("MainWindowGeometry", QucsMain->saveGeometry()); } diff --git a/qucs/schematic_file.cpp b/qucs/schematic_file.cpp index e6061fee1..34a0330c2 100644 --- a/qucs/schematic_file.cpp +++ b/qucs/schematic_file.cpp @@ -1070,7 +1070,7 @@ bool Schematic::loadDocument() QFile file(DocName); if(!file.open(QIODevice::ReadOnly)) { /// \todo implement unified error/warning handling GUI and CLI - if (QucsMain) + if (QucsMain != nullptr) QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Cannot load document: ")+DocName); else @@ -1509,7 +1509,7 @@ bool Schematic::throughAllComps(QTextStream *stream, int& countInit, delete d; /// \todo implement error/warning message dispatcher for GUI and CLI modes. QString message = QObject::tr("ERROR: Cannot load subcircuit \"%1\".").arg(s); - if (QucsMain) // GUI is running + if (QucsMain != nullptr) // GUI is running ErrText->appendPlainText(message); else // command line qCritical() << "Schematic::throughAllComps" << message;