我在qt gui中编写了一个记事本,但是当我将文件与之关联并单击时,.exe会运行且文件不会打开,因此我必须使用
QFileDialog::getSaveFileName(
this,"Save As","",
"Text Document (*.txt)\n All Files (*.*)")
当我们单击text.txt时,它将直接在记事本中打开文件。如何为我的应用制作相同的图片?
备注: QDir :: currentpath()返回我们单击的file.txtq(与之关联)的路径,但我无法返回其名称。
双击文件(与您的exe相关联)时,其路径会通过命令行参数传递给您的程序。您可以通过以下方式访问它们:
if (QApplication::arguments().size() > 1) {
const QString filename = QApplication::arguments().at(1);
// "filename" now contains path and name of the file to open.
}
另外,我不知道您为什么使用QFileDialog::getSaveFileName()
。为了调用打开文件对话框,您将需要QDialog::getOpenFileName()
方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句