文件管理 · 2022年8月15日

qfile文件名|qt如何打开一个指定文件

⑴ qt怎么读取一个文件夹下的所有文件名

QFileInfoList QDir::entryInfoList(const QStringList & nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) const

⑵ Qt中如何生成文件名

1.添加库文件静态库linux:LIBS += your_lib_path/your_lib动态库linux:LIBS += -L your_lib_path -lyour_lib//经过测试了win32:LIBS += your_lib_path/your_lib例如:LIBS += -L lib/pcsc/ -lpcscliteLIBS += lib/pcsc/libpcsclite.a2.添加头文件INCLUDEPATH += your_include_path例如:INCLUDEPATH += . /usr/local/include(点号后面有空格)3.添加要编译的源文件和头文件SOURCES:所有源文件列表HEADERS:所有头文件列表FORMS:所有.ui文件列表前期工作:1.检查gcc,g++,qmake是否用错。2.在Makefile中检查是否少了头文件3.检查是否与<错用了4.需要另外加库的程序最好单独建一个文件

⑶ qt 如何得到正在运行程序文件名

QApplication a(argc, argv); mainDialog w; w.show(); return a.exec();如果以上面的程序为例,程序运行时,argc=1,argv中记录着程序的完整路径,比如:d:/qt/demo.exe,楼主可以通过这个得到正在运行的文件名demo.exe。祝愉快~

⑷ 如何从gamit的qfile中获取时间序列

QFile类是一个操作文件的输入/输出设备。 详情请见……#include <qfile.h>继承了 QIODevice。所有成员函数的列表。公有成员QFile ()QFile ( const QString & name )~QFile ()QString name () constvoid setName ( const QString & name )typedef QCString (* EncoderFn ) ( const QString & fileName )typedef QString (* DecoderFn ) ( const QCString & localfileName )bool exists () constbool remove ()virtual bool open ( int m )bool open ( int m, FILE * f )bool open ( int m, int f )virtual void close ()virtual void flush ()virtual Offset size () constvirtual Offset at () constvirtual bool at ( Offset pos )virtual bool atEnd () constvirtual Q_LONG readBlock ( char * p, Q_ULONG len )virtual Q_LONG readLine ( char * p, Q_ULONG maxlen )Q_LONG readLine ( QString & s, Q_ULONG maxlen )virtual int getch ()virtual int putch ( int ch )virtual int ungetch ( int ch )int handle () const静态公有成员QCString encodeName ( const QString & fileName )QString decodeName ( const QCString & localFileName )void setEncodingFunction ( EncoderFn f )void setDecodingFunction ( DecoderFn f )bool exists ( const QString & fileName )bool remove ( const QString & fileName )重要的继承成员virtual QByteArray readAll ()详细描述QFile类是一个操作文件的输入/输出设备。QFile是用来读写二进制文件和文本文件的输入/输出设备。QFile可以自己单独被使用,但是如果和QDataStream或QTextStream一起使用将更加方便。文件名通常可以通过构造函数来传递,但也可以使用setName()来设置。你可以通过exists()来检查一个文件是否存在并且可以通过remove()来移去一个文件。文件可以用open()来打开、用close()来关闭、用flush()来刷新。数据通常可以使用QDataStream或者QTextStream进行读写,但你也可以使用readBlock()和readLine()来读,使用writeBlock()来写。QFile也支持getch()、 ungetch()和putch()。size()可以返回文件的大小。你可以通过使用at()函数得到当前文件位置或者移到一个新的文件位置。如果你到了文件的末尾,atEnd()返回真。handle()返回文件句柄。这里是一个使用QTextStream来一行一行地读取一个文本文件的代码段。它会把每一行带上一个行号打印出来。 QStringList lines; QFile file( "file.txt" ); if ( file.open( IO_ReadOnly ) ) { QTextStream stream( &file ); QString line; int n = 1; while ( !stream.eof() ) { line = stream.readLine(); // 不包括“\n”的一行文本 printf( "%3d: %s\n", n++, line.latin1() ); lines += line; } file.close(); }写文本也很容易(假设我们有一个行的字符串列表要写): QFile file( "file.txt" ); if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) stream << *it << "\n"; file.close(); }QFileInfo类控制文件的详细信息,比如访问权限、文件日期和文件类型。QDir类管理目录和文件名列表。Qt使用Unicode文件名。如果你想在Unix系统上使用你自己的输入/输出,你可以使用encodeName()(和decodeName())来把文件名转换为本地编码。也可以参考QDataStream、QTextStream和输入/输出和网络。

⑸ qt如何打开一个指定文件

QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo("文件名.文件后缀").absoluteFilePath()));

⑹ qt中连接到ftp服务器上后怎么获取服务下所有的文件名

操作方法如下:@echo offset h=192.168.1.100set u=ftpuserset p=12345678echo open %h%>ftp.txtecho %u%>>ftp.txtecho %p%>>ftp.txtecho dir>>ftp.txtecho bye>>ftp.txtftp -s:ftp.txt>ftpdir.txtecho open %h%>ftp.txtecho %u%>>ftp.txtecho %p%>>ftp.txtfor /f "tokens=4" %%i in ('findstr "<DIR>" ftpdir.txt') do (echo cd %%~i>>ftp.txtecho dir>>ftp.txtecho cd ..>>ftp.txt)echo bye>>ftp.txtftp -s:ftp.txt>ftpfile.txtnotepad ftpfile.txt

⑺ QT编程中对于文件操作的程序讲解,最好是把下面的程序一句一句的解释下:在线等,十分感谢

void funlibEdit::InitTypeData(){//读基本类型QFile file("datatype"); //datatype为读取的文件名,这里可以为路径,否则表示为当前路径if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) //设置为Text方式只读,并判断是否打开return; //若打开失败直接返回QTextStream in(&file); //将内容读到文本流中,即in中为datatype中的所有内容while (!in.atEnd()) //循环遍历到结束{QString loctype = in.readLine(); //读一行到locttupeloctype = loctype.simplified(); //这个应该是化简,具体我不清楚,你可以去看下手册simplified的函数功能m_typelist.append(loctype); //在m_typelist这段字符串之后加上loctype这个字符串}file.close(); //关闭打开的datatype文件//读类型映射QFile mapfile("datatypemap");if (!mapfile.open(QIODevice::ReadOnly | QIODevice::Text)) //同上判断return;QTextStream mapin(&mapfile); //同上while (!mapin.atEnd()) //同上{QString mapline = mapin.readLine(); //同上int index = mapline.indexOf(":"); //所以“:”,返回位置QString outtype = mapline.left(index).simplified(); //同上QString intype = mapline.right(mapline.length()-index-1).simplified(); //同上m_typemap[outtype] = intype; //放到数组中,功能同上}mapfile.close(); //同上}

⑻ qt中如何以字符数组为名创建一个txt文件

charss[20]="abcd";QStringfn=QString::fromLatin1(ss);//先转换成Qstring类型fn+=".txt";//你要的txt格式QFilefile(fn);//这个fn也可以加上路径if(!file.open(QFile::ReadWrite|QFile::Text))//open()可以创建文件{//openmode可以自定义qDebug()<<"fileopenerror";}//…文件操作file.close();//最后要close

⑼ qt activedoccument文件名称

从获取的文件中分解,然后提取正确的路径获得文件名称。先从getOpenFile获取整个文件信息,然后利用QFileInfo进行分解,从而获得正确的文件名、后缀和绝对路径。这样得出的文件名称就是格式正确且存储正常的。实际编程中,我们会发现,getOpenFileName这个方法获取的文件名往往带有路径,比如我想获得的文件名是abc.doc,可是调用在这个函数获得的确实是C:abd.doc,导致文件名称与路径不匹配,使用上述方法就可以获取正确的文件名称了。

⑽ qt文件读取

1、Qt 作为一个通用开发库,提供了跨平台的文件操作能力。文件操作是应用程序必不可少的部分。2、Qt5增加了QFileDevice类。途中所涉及的类及其用途简要说明如下:· QFlie:访问本地文件或者嵌入资源;· QTemporaryFile:创建和访问本地文件系统的临时文件;· QBuffer:读写QByteArray;· QProcess:运行外部程序,处理进程间通讯;· QTcpSocket:TCP协议网络数据传输;· QUdpSocket:传输 UDP 报文;· QSslSocket:使用 SSL/TLS 传输数据;· QFileDevice:新增加的类,提供了有关文件操作的通用实现。3、这其中,QProcess、QTcpSocket、QUdpSoctet和QSslSocket是顺序访问设备。所谓“顺序访问”,是指它们的数据只能访问一遍:从头走到尾,从第一个字节开始访问,直到最后一个字节,中途不能返回去读取上一个字节;QFile、QTemporaryFile和QBuffer是随机访问设备,可以访问任意位置任意次数,还可以使用QIODevice::seek()函数来重新定位文件访问位置指针。4、QFile主要提供了有关文件的各种操作,比如打开文件、关闭文件、刷新文件等。我们可以使用QDataStream或QTextStream类来读写文件,也可以使用QIODevice提供的read()、readLine()、readAll()以及write()这样的函数。值得注意的是,有关文件本身的信息,比如文件名、文件所在目录的名字等,则是通过QFileInfo获取,而不是自己分析文件路径字符串。5、举个例子,打开文件时,需要参数指定打开文件的模式:Constant Value Description QIODevice::NotOpen 0x0000 The device is not open. QIODevice::ReadOnly 0x0001 The device is open for reading. QIODevice::WriteOnly 0x0002 The device is open for writing. QIODevice::ReadWrite ReadOnly | WriteOnly The device is open for reading and writing. QIODevice::Append 0x0004 The device is opened in append mode, so that all data is written to the end of the file. QIODevice::Truncate 0x0008 If possible, the device is truncated before it is opened. All earlier contents of the device are lost. QIODevice::Text 0x0010 When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32.QIODevice::Unbuffered 0x0020 Any buffer in the device is bypassed.