在QT中返回对话框时遇到错误:

时间:2017-10-13 10:45:50

标签: c++ qt

我正在尝试将QMessageBox的指针从一个函数返回到另一个函数,但是我面对以下错误:

  

错误:'QMessageBox :: QMessageBox(const QMessageBox&)'是私有的        Q_DISABLE_COPY(QMessageBox提示)

代码:

QMessageBox BoxDraw()
{
QMessageBox *msgBox;
bool retValue=false;
msgBox->setWindowTitle("");
QString qstr = QString::fromStdString(MY_String);
QString qyes = QString::fromStdString(MY_String_YES);
QString qno = QString::fromStdString(MY_String_NO);
msgBox->setText(qstr);
msgBox->setParent(0);
msgBox->setWindowFlags(Qt::Window);
msgBox->setWindowFlags(Qt::BypassWindowManagerHint);
return *msgBox;
}

从另一个函数调用它,如:

*global variable* 
QMessageBox *diagBox = NULL;

func A()
{
diagBox = BoxDraw();
}

1 个答案:

答案 0 :(得分:1)

您无法复制QMessageBox。返回一个指针

QMessageBox* BoxDraw()
{
   QMessageBox *msgBox;
   ...    
   return msgBox;
}

顺便说一句:你错过了new QMessageBox

相关问题