Qt二题:QString的输出和QDialog的退出

来源:互联网 发布:centos下安装图形界面 编辑:程序博客网 时间:2024/06/02 02:40

QString的输出:

QString path; const char *p = path.toLocal8Bit().data();

printf("%s,%d,%s/n",__func__,__LINE__,p);

 

 

QDialog的退出:

如果是指向QDialog类的指针,则:

((QDialog *)this)->done(0);

如果是QDialog,直接调用其done函数即可.

其实我一开始也不知道QDialog是如何退出的.太久没用了,忘记了.

而且通过搜索的到的结果也很乱.索性直接去看源代码,这个就解释的很清楚了:

/*!
  Closes the dialog and sets its result code to /a r. If this dialog
  is shown with exec(), done() causes the local event loop to finish,
  and exec() to return /a r.

  As with QWidget::close(), done() deletes the dialog if the
  Qt::WA_DeleteOnClose flag is set. If the dialog is the application's
  main widget, the application terminates. If the dialog is the
  last window closed, the QApplication::lastWindowClosed() signal is
  emitted.

  /sa accept(), reject(), QApplication::activeWindow(), QApplication::quit()
*/

void QDialog::done(int r)
{
    Q_D(QDialog);
    hide();
    setResult(r);

    d->close_helper(QWidgetPrivate::CloseNoEvent);
    d->resetModalitySetByOpen();

    emit finished(r);
    if (r == Accepted)
        emit accepted();
    else if (r == Rejected)
        emit rejected();
}