我有一個簡單的gui,它有一個文本字段,一個下拉菜單和一個go按鈕。我可以指定我正在查找的零件的名稱和類別,並通過將「go」按鈕連接到一個運行我已經創建的功能的插槽來調用一個函數。Qt C++函數中斷刪除未知變量
但是,當插槽功能完成所有事情時,它會調用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是不是應該回來,以便我可以指定一個新對象?我怎樣才能讓它不要刪除這個對象,或讓它成功?
聲音就像你在程序中崩潰一樣,與信號和插槽完全無關 – Chris
我只是在'on_go_clicked()'函數調用函數後添加'QApplication :: exit()',並且它執行退出,但gui沒有關閉,程序仍然中斷。 –
克里斯,功能運行後,我的程序中不應該發生任何事情。我寫了沒有函數的gui,並且它工作。我沒有gui寫了這個函數,它起作用了。我把函數放在gui中,它調用函數,完成並返回到gui,但當插槽函數完成時會崩潰。 –