#include "fileinfo.h"
#include "ui_fileinfo.h"
#include
#include
#include
#include
#include
fileinfo::fileinfo(QWidget *parent) :
QWidget(parent),
ui(new Ui::fileinfo)
{
ui->setupUi(this);
this->setMaximumSize(470,290);
this->setMinimumSize(470,290);
QObject::connect(ui->OpenFloderpushButton,SIGNAL(clicked()),this,SLOT(getFileInfoSlot()));
}
fileinfo::~fileinfo()
{
delete ui;
}
void fileinfo::getFileInfoSlot()
{
QString fileName=QFileDialog::getOpenFileName(this,"Open File",QDir::homePath());
if(fileName.isEmpty())
{
QMessageBox::information(this,"Error Message","Please Select a File");
return;
}
QFileInfo info(fileName);
ui->FileSizelineEdit->setText(QString::number(info.size()));//get file size qint64
QDateTime create=info.created();
ui->FileCreateDatelineEdit->setText(create.toString("yyyy-MM-dd hh:mm:ss"));
QDateTime lastRead=info.lastRead();
ui->lastAccesslineEdit->setText(lastRead.toString("yyyy-MM-dd hh:mm:ss"));
if(info.isDir())
{
ui->IsDirectorylineEdit->setText("是");
}
else
{
ui->IsDirectorylineEdit->setText("不是目录");
}
}
void fileinfo::on_closepushButton_clicked()
{
this->close();
}
b>.main.cpp Source Code:
#include "fileinfo.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString strPath=QApplication::applicationDirPath();
strPath+="/fonts.png";
a.setWindowIcon(QIcon(strPath));
fileinfo w;
w.show();
return a.exec();
}
c.>.fileinfo.h Source Code:
#ifndef FILEINFO_H
#define FILEINFO_H
#include
#include
#include
#include
#include
#include
namespace Ui {
class fileinfo;
}
class fileinfo : public QWidget
{
Q_OBJECT
public:
explicit fileinfo(QWidget *parent = 0);
~fileinfo();
private:
Ui::fileinfo *ui;
private slots:
void getFileInfoSlot();//用于获当前文件的属性信息
void on_closepushButton_clicked();
};
#endif // FILEINFO_H
d>.fileinfo_1.pro Source Code:
#-------------------------------------------------
#
# Project created by QtCreator 2018-06-27T16:20:03
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = fileinfo_1
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
fileinfo.cpp
HEADERS += \
fileinfo.h
FORMS += \
fileinfo.ui
RC_FILE=icon.rc