简体   繁体   中英

Qt6: "Unable to read Memory" when pointing to a QLineEdit from a QFormLayout

I want to get the text from a QLineEdit, which is in a QFormLayout, to save it to a File. The saving works fine, but I am not able to get the text form the QLineEdit and when I look at it from the Debugger it says "Unable to read Memory". I can´t figure out how to correctly point to the QLineEdit, so that I can get the text.

With this code I want to get the text:

QJsonArray Kegelbuch::saveSettings() {
    QFormLayout* formLayout = (QFormLayout*)ui.einstellungenTab->layout();
    QJsonArray data;
    QLineEdit* settingsEdit;

    for (int i = 0; i < formLayout->rowCount(); i++) {
        settingsEdit = (QLineEdit*)formLayout->itemAt(i, QFormLayout::ItemRole::FieldRole);
    }

    return data;
}

How the window looks: 智能标签

Replace

settingsEdit = (QLineEdit*)formLayout->itemAt(i, QFormLayout::ItemRole::FieldRole);

with

settingsEdit = (QLineEdit*)(formLayout->itemAt(i, FormLayout::ItemRole::FieldRole)->widget());

Background: itemAt() returns a QLayoutItem* , so you need to call QWidget *QLayoutItem::widget() to get the widget.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM