如何解决QLineEdit :: text返回非字符串
获取QLineEdit的文本值时遇到一个奇怪的问题。
在QWidget上有一个QLineEdit和QDialogButtonBox。单击“确定”按钮后,将读取并保存QLineEdit的值。
这是我的代码:
properties.h
#ifndef PROPERTIES_H
#define PROPERTIES_H
#include "config.h"
#include <QtWidgets/QDialog>
namespace Ui {
class properties;
}
class properties : public QDialog {
Q_OBJECT
public:
explicit properties(QWidget *parent = nullptr);
~properties();
private slots:
void on_buttonBox_accepted();
private:
Ui::properties *pProp;
};
#endif // PROPERTIES_H
properties.cpp
#include <cstdio>
#include "properties.h"
#include "Form.h"
#include "ui_properties.h"
#include <QtWidgets/QFileDialog>
properties::properties(QWidget *parent) : QDialog(parent),pProp(new Ui::properties) {
pProp->setupUi(this);
pProp->NameEdit->setText(QString("test"));
}
properties::~properties() { delete pProp; }
void properties::on_buttonBox_accepted() {
QString qstr = pProp->NameEdit->text();
std::string stdstr = qstr.toStdString();
const char *cstr = stdstr.c_str();
qDebug() << "qDebug: " << pProp->NameEdit->text();
std::cout << "cout stdstr: " << stdstr;
this->close();
}
输出为
qDebug: "test"
cout stdstr:
,它崩溃并显示为“运行时检查失败#2-变量'stdstr'周围的堆栈已损坏”。离开方法时。
当我使用Visual Studio调试器检查stdstr时,其内容类似于“à
我想念什么?
谢谢您的建议。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。