• 9432阅读
  • 6回复

如何实现新建或打开一个xml文件 [复制链接]

上一主题 下一主题
离线pply1860
 
只看楼主 倒序阅读 楼主  发表于: 2007-08-16
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
想实现一个功能:到指定目录下打开指定名字(NoticeList.xml)的文件,如果不存在则新建一个同名文件。可是实现不了。代码如下:              
                     QString path;
    path = QDir::homePath().append("/My Documents/NoticeList.xml") ;
    QFileInfo info(path);
   
    if (!info.exists())
           QFile file = new QFile("NoticeList.xml",QDir::homePath().append("/My Documents"));

报错是:
noticeinfowidget.cpp:193: error: no matching function for call to `QFile::QFile(
const char[15], QString&)'
刚学Qt,比较菜,大家看一下该怎么改,谢谢
[ 此贴被XChinux在2007-08-17 20:03重新编辑 ]
learning
离线XChinux

只看该作者 1楼 发表于: 2007-08-16
人家报错信息都告诉你了,
QFile *file = new QFile(...)
你缺少一个星号
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线pply1860
只看该作者 2楼 发表于: 2007-08-16
我把那个地方改成
  QFile *file = new QFile("NoticeList.xml",QDir::homePath().append("/My Documents"));
还是有问题啊:
noticeinfowidget.cpp:193: error: no matching function for call to `QFile::QFile(
const char[15], QString&)'
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:168: note: candidates ar
e: QFile::QFile(const QFile&)
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:160: note:
  QFile::QFile(QFilePrivate&, QObject*)
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:84: note:
  QFile::QFile(const QString&, QObject*)
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:83: note:
  QFile::QFile(QObject*)
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:81: note:
  QFile::QFile(const QString&)
C:/Qt/4.2.0/include/QtCore/../../src/corelib/io/qfile.h:80: note:
  QFile::QFile()
noticeinfowidget.cpp:193: warning: unused variable 'file'
learning
离线pply1860
只看该作者 3楼 发表于: 2007-08-17
QFile *file = new QFile("NoticeList.xml",QDir::homePath().append("/My Documents"));
是模仿API里构造函数QFile::QFile ( const QString & name, QObject * parent )
想在“我的文档”里新建一个名为“NoticeList.xml”的文件。
不知道正确的该怎么写?
learning
离线jzj139
只看该作者 4楼 发表于: 2007-08-18
QObject * parent

QDir::homePath().append("/My Documents")


你再看看
qt
离线pply1860
只看该作者 5楼 发表于: 2007-08-20
现在知道如何打开一个文件,比如打开在C:\Documents and Settings\nc\My Documents\的noticelist.xml
可以这样写:QFile file("C:/Documents and Settings/nc/My Documents/noticelist.xml");
然后在进行各种操作。但如何新建一个文件呢?
比如想在C:\Documents and Settings\nc\My Documents\里新建一个名为noticelist.xml的文件,该怎么写啊?
learning
离线pply1860
只看该作者 6楼 发表于: 2007-08-21
大家帮忙看一下吧,光看API我实在是不知道怎么新建文件啊,谢谢了
learning
快速回复
限100 字节
 
上一个 下一个