diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index 5c5578ed9..515aa2d8b 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -1347,8 +1347,13 @@ void DynamicElementTextItem::updateLabel() } else if (m_text_from == CompositeText) { // Use actualLabel() to ensure %{label} reflects the current - // resolved label (e.g. after a folio/page-number change) - dc.addValue(QStringLiteral("label"), element->actualLabel()); + // resolved label (e.g. after a folio/page-number change). + // A contact not linked to a coil has no element to read from + // (bugtracker #345): %{label} then shows empty, as it did + // before actualLabel() was used here. + if (element) { + dc.addValue(QStringLiteral("label"), element->actualLabel()); + } setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, dc)); } } diff --git a/tests/qttest/fixtures/unlinked_contact_label.qet b/tests/qttest/fixtures/unlinked_contact_label.qet new file mode 100644 index 000000000..e3ad9481e --- /dev/null +++ b/tests/qttest/fixtures/unlinked_contact_label.qet @@ -0,0 +1,315 @@ + + + 10/2/26 + 02-10-2026 + 2026-10-02 + skeleton + /tmp/qet-mcp-new-k41dmnyo/skeleton.qet + 18:39 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + label + + + + %{label} + + + + + + + + + + Elements importats + Zavedené prvky + Importerede elementer + Importierte Elemente + Εισηγμένα στοιχεία + Imported elements + Elementos importados + Éléments importés + Uvezeni elementi + Elementi importati + インバートされた要素 + 전기 심볼 요소 + 전기 심볼 요소 + Elementen geïmporteerd + Elementen geïmporteerd + Elementy importowane + Elementos importados + Elementos importados + Elemente importate + Импортированные элементы + Uvoženi elementi + Importerade element + İthal öğeler + Імпортовані елементи + 导入元件 + + + + كهربائي + Elèctric + Elektrotechnika + Elektrisk + Elektrik + Ηλεκτρικά + Electric + Eléctrica + Sähkö + Electrique + Električno + Elektromos + Elettrica + 電気 + 전기 + Цахилгаан + Elektrisk + Elektrotechniek + Elektrisch + Elektrotechnika + Elétrico + Elétrica + Electric + Электротехника + Elektrické + Elektrika + Електрика + El + Elektrik + Електрика + 10_电气 + 电气工程 + + + + متعدد الأقطاب + Multifilar + Vícežilový + Flere ledere + Allpolig + Πολυγραμμικό + All-pole + Multifilar + Yleisnapa + Multifilaire + Univerzalni + Többvonalas szimbólumok + Multifilare + 複線 + 다-극 + Бүх туйл + Alle poler + Veel polig + All-pole + Schematy wieloliniowe + Multipolar + Multifilar + Bipolar + Многополюсные + Všepólové + Vsi poli + Свe-полни + Allpolig + Çok kutuplu + Багатополюсні + 10_全极 + + + + المرحّلات والموصّلات وجهات الاتصال + Relés, contactors i contactes + Relé, stykače a kontakty + Relæer, kontaktorer og kontakter + Relais, Schütze und Kontakte + Ηλεκτρονόμοι και επαφές + Relays, contactors and contacts + Relevadores, contactores y contactos + Releet, kontaktorit ja koskettimet + Relais, contacteurs et contacts + Releji, kontaktori i kontakti + Relék, kontaktorok és érintkezők + Relè, contattori e contatti + 継電器、接触器、接点 + 릴레이, 커넥터및 접점 + Реле, контактор болон контакт + Reléer, kontaktorere og kontakter + Relais, contactoren en contacten + Relais, contacteurs en contacten + Przekaźniki i styczniki + Relés, contatores e contactos + Relés, Contatores e contatos + Relee, contactoare și contacte + Реле, пускатели и контакты + Relé, stykače a kontakty + Releji, kontaktorji in kontakti + Релеји, контактори и контакти + Reläer, kontaktorer och kontakter + Röleler, kontaktörler ve kontaklar + Реле, контактори та контакти + 继电器、接触器与触点 + + + + تماسات مع إحالات + Contactes amb referències creuades + Kontakty s křížovými odkazy + Kontaker med krydsreference + Kontakte mit Querverweis + Επαφές με παραπομπές + Contacts with cross referencing + Contactos con referencia cruzada + Kosketimet lehtiviittauksella + Contacts avec référence croisée + Kontakti s unakrsnim referenciranjem + Érintkezők kereszthivatkozásokkal + Contatti con riferimenti incrociati + 相互参照付き接点 + 교차 참조 접점 + Харилцан холбоос бүхий контакт + Kontakter med kryssreferanse + Contacten met kruisreferentie + Contacten met kruisverwijzing + Zestyki (automatyczne oznaczenia) + Contactos com renvoi de folio + Contatos com referencia cruzada + Contacte cu renvoi de folio + Контакты с перекрестными ссылками + Kontakty s krížovým odkazom + Kontakti s sklici + Контакти са унакрсним референцирањем + Kontakter med bladhänvisning + Çapraz referanslı kontaklar + Контакти з перехресними посиланнями + 触点交叉引用 + + + + حمايات + Proteccions + Ochrany + Beskyttelsesfunktioner + Schutzfunktion + Προστασία + Protections + Protecciones + Suojaukset + Protections + Zaštite + Védelmek + Protezioni + 保護 + 보호 접점 + Хамгаалалт + Beskyttelser + Beveiliging + Beveiligingen + Zabezpieczenia + Protecções + Protecções + Protecții + Защитные уст-ва + Ochrany + Zaščite + Заштите + Skydd + Korumalar + Захисти + 保护触点 + + + + + + مُلامس مُرحّل حراري (NC) + Relé tèrmic de contacte (NC) + Kontakt (NC) tepelného jističe + Kontakt termisk relæ (NC) + Relaisöffner + Επαφή θερμικού κλειστή + Contact thermal relay (NC) + Contacto relé térmico NC + Kosketin lämpörele (NC) + Contact relais thermique (NF) + Kontakt termičkog releja (NC) + Hőrelé érintkező (NC) + Contatto relé térmico (NC) + 接点 熱動継電器 (NC) + 접점 열 릴레이 (NC) + Дулааны релений контакт (NC) + Kontakt termisk relé (NC) + Thermisch bediend contact (NC) + Contact thermisch relais (NC) + Zestyk rozwierny przekaźnika cieplnego + Contacto relé térmico (NC) + Contato de relé térmico (NF) + Contact releu termic (NC) + Контакт теплового реле (НЗ) + Kontakt tepelného relé (NC) + Kontakt termičnega releja (NC) + Контакт термичког релеја (NC) + Kontakt termiskt relä (NC) + Termik röle kontağı (NC) + Контакт теплового реле (NC) + 继电器常闭从属触点 + + + simple + NC + 1 + + Author: The QElectroTech team +License: see http://qelectrotech.org/wiki/doc/elements_license + + + + + + + label + + + + + + + + + + + + + + + + diff --git a/tests/qttest/tst_resaveunchanged.cpp b/tests/qttest/tst_resaveunchanged.cpp index 55fed0942..252457dd3 100644 --- a/tests/qttest/tst_resaveunchanged.cpp +++ b/tests/qttest/tst_resaveunchanged.cpp @@ -17,8 +17,9 @@ // - information values were trimmed on save but not on load, so a label // with stray spaces kept them in its displayed copy until the project // was opened again (m_000.qet). -// Runs the real binary's --resave twice on every example, and on a -// project whose title block holds a value that is a single space (#973). +// Runs the real binary's --resave twice on every example, on a project +// whose title block holds a value that is a single space (#973), and on +// one that used to crash on opening (bugtracker #345). class tst_resaveunchanged : public QObject { Q_OBJECT @@ -83,6 +84,20 @@ private slots: QVERIFY2(a == b, "the second save changed the file"); } + // A contact not linked to a coil, carrying a text built from %{label}: + // opening it dereferenced the missing coil and crashed (bugtracker #345). + // The fixture is a blank project with one such contact. + void unlinkedContactLabelTextOpens() + { + const QString fixture = QFINDTESTDATA("fixtures/unlinked_contact_label.qet"); + QVERIFY(!fixture.isEmpty()); + const QString first = resave(fixture); + QVERIFY2(!first.isEmpty(), "--resave failed: QElectroTech crashed opening the project"); + const QString second = resave(first); + QVERIFY2(!second.isEmpty(), "second --resave failed"); + QVERIFY2(read(first) == read(second), "the second save changed the file"); + } + // A title-block value that is a single space is kept through two saves // (#973), and a value with accents comes back as it went in. void singleSpaceValueKept()