Qt C++函数中断删除未知变量
Qt C++ function breaks deleting unknown variable
我有一个简单的gui,它有一个文本字段、一个下拉菜单和一个go按钮。我可以指定我要查找的部件的名称和类,并通过将"go"按钮连接到运行我已经创建的函数的插槽来调用函数。
然而,当slot函数处理完所有内容时,它会调用xstring
中的一个函数,即删除一些大量的xstring
。它转到这个功能:
void _Tidy(bool _Built = false,
size_type _Newsize = 0)
{ // initialize buffer, deallocating any storage
if (!_Built)
;
else if (this->_BUF_SIZE <= this->_Myres)
{ // copy any leftovers to small buffer and deallocate
pointer _Ptr = this->_Bx._Ptr;
this->_Getal().destroy(&this->_Bx._Ptr);
if (0 < _Newsize)
_Traits::copy(this->_Bx._Buf,
_STD addressof(*_Ptr), _Newsize);
this->_Getal().deallocate(_Ptr, this->_Myres + 1);
}
this->_Myres = this->_BUF_SIZE - 1;
_Eos(_Newsize);
}
我的程序在this->_Getal().deallocate(_Ptr, this->_Myres + 1);
执行一个中断。
这是gui的代码:
#include <QtGui>
#include <QApplication>
#include <QComboBox>
#include "gui.h"
#include <vector>
std::vector<std::string> PartClasses;
gui::gui(QWidget *parent) : QDialog(parent){
getPartClasses(PartClasses); //my own function, does not affect how the gui runs, just puts strings in PartClasses
label1 = new QLabel(tr("Insert Name (Optional):"));
label2 = new QLabel(tr("Class Name (Required):"));
lineEdit = new QLineEdit;
goButton = new QPushButton(tr("&Go"));
goButton->setDefault(true);
connect(goButton, SIGNAL(clicked()), this, SLOT(on_go_clicked()));
cb = new QComboBox();
for(int i = 0; i < PartClasses.size(); i++)
cb->addItem(QString::fromStdString(PartClasses[i]));
//*add widgets to layouts, removed for space*
setWindowTitle(tr("TEST"));
setFixedHeight(sizeHint().height());
}
void gui::on_go_clicked(){
std::string str(cb->currentText().toStdString());
updateDB(str, lineEdit->text().toUtf8().constData()); //my function, does not affect the gui.
QApplication::exit();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
gui *stuff = new gui;
stuff->show();
return app.exec();
}
它在做什么?当我完成了这个插槽时,gui不应该重新出现,这样我就可以指定一个新的对象吗?我如何才能使它不删除此对象,或者使它成功?
以下是我对正在发生的事情的最佳猜测:
您正在访问的对象正在某个不该删除的地方被删除。
_Tidy
函数看起来像是在字符串操作之后进行一些清理。很可能你的char *
的常量没有降下来,你正在删除一个常量指针。
为了解决这个问题,我会对您的变量进行深度复制,并将其传递到执行xstring
LaTex的updateDB
中。或者,您可以立即创建一个xstring对象并将其传递下去。
我也会考虑使用strcpy
或类似的东西,或者可能只是std::string
。
此外,出现的崩溃代码也会有所帮助。
编辑:
以下是您的代码可能应该是什么样子。。。
void gui::on_go_clicked(){
std::string str(cb->currentText().toStdString());
std::string line_edit_str(lineEdit->text().toUtf8().constData());
updateDB(str, line_edit_str); //my function, does not affect the gui.
QApplication::exit();
}
希望能有所帮助。
相关文章:
- 如何从未知视图中声明范围::v3::View 变量
- 通过 C++ 中的重载构造函数初始化未知类型的变量
- C++:将未知类型的对象存储为成员变量的类
- 如何将局部变量初始化为C++的未知值
- 局部变量显式启动为零,并且在 C++ 语言中没有未知值
- 从C++调用 Python 或 Lua 来计算表达式,仅在需要时计算未知变量
- ExprTK 未知变量分辨率取决于表达式类型
- 如何创建一个未知数变量和未知类型变量的构造函数
- 字符串流到具有未知分隔符的变量
- 变量错误:未知类型名称
- C 通过未知名的变量到方法
- C++ 中的未知变量声明语法
- C++未知变量类型.我应该使用模板吗
- 如何在if/else序列中定义未知类型的全局变量
- 如何保存类用户传递的未知变量
- 带有变量且参数数量未知的c++函数
- 变量因未知原因而更改
- Wt Dbo MySQL 后端连接错误"SET storage_engine=INNODB;":未知的系统变量'storage_engine'
- Qt C++函数中断删除未知变量
- 如何为未知容器声明迭代器变量