Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Get the file information in Qt

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Creator IDE V 4.5 and Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Article
Keywords: QFileInfo
Created: mind_freak (10 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This article shows how to use QFileInfo to get name and modification information about a file in the file system. QFileInfo objects are used to hold information about files and directories.


The method used in the case are given below :

  • fileName() : Returns the name of the file, excluding the path.
  • lastModified() :Returns the date and time when the file was last modified.
  • suffix() : Returns the suffix of the file.The suffix consists of all characters in the file after (but not including) the last '.'.

Preconditions

  • Download and install the Qt SDK.


Property

  • Returns the canonical path including the file name, i.e. an absolute path without symbolic links or redundant "." or ".." elements.
str=Info->canonicalFilePath ();
  • Returns the complete base name of the file without the path.
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.completeBaseName();  // base = "archive.tar"

Source File

Main.cpp

#include <QtGui/QApplication>
#include "fileinfo.h"
#include<QFileInfo>
#include<QWidget>
#include<QLabel>
#include<QString>
#include<QVBoxLayout>
#include<QDateTime>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win=new QWidget();
QDateTime time;
QFileInfo info("C://demos//launcher//install.txt");
QString str=info.fileName();
time=info.lastModified();
QString str1;
str1=time.toString();
QString ext = info.suffix();
QLabel *lbl=new QLabel(str);
QLabel *lbl1=new QLabel(str1);
QLabel *lbl2=new QLabel(ext);
QVBoxLayout *lay=new QVBoxLayout();
lay->addWidget(lbl);// Name of file "Intall.txt"
lay->addWidget(lbl1);//Last Modified Date
lay->addWidget(lbl2);//File Extension
win->setLayout(lay);
win->show();
return a.exec();
}

Screen shot

Fileinfo.JPG

Creator IDE

Fileinfo1.JPG


Author - User:Mind freak

This page was last modified on 11 October 2012, at 01:16.
306 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×