티스토리 뷰

프로그래밍/Qt

Qt 강좌 21 QDir 디렉토리 만들기

뽀로로친구에디 2018. 9. 16. 16:27

Qt 강좌 21 QDir 디렉토리 만들기


1. 레이아웃 



2. 다음과 같은 컨트롤 사용 (comboBox, listWidget, push Button)



3. 예제 레이아웃



4. 소스코드 



5. 소스코드 


#include "mainwindow.h"

#include "ui_mainwindow.h"

#include <QDir>

#include <QMessageBox>


MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    ui->setupUi(this);

    QDir dir;


    foreach(QFileInfo var, dir.drives())

    {

        ui->comboBox->addItem(var.absoluteFilePath());

    }


    QDir dir_2("/home/pi");

    foreach(QFileInfo var, dir_2.entryInfoList())

    {

        if(var.isDir()) //디렉토리일 경우

            ui->listWidget->addItem("Dir: "+var.absoluteFilePath());

        if(var.isFile()) //파일일 경우

            ui->listWidget->addItem("File: "+var.absoluteFilePath());


    }


}


MainWindow::~MainWindow()

{

    delete ui;

}


void MainWindow::on_pushButton_clicked()

{

    // /home/pi/hello 폴더가 없으면 폴더를 만든다. 

     QDir dir("/home/pi/hello"); 

     if(dir.exists())

     {

         QMessageBox::information(this,"","dir exists");


     }

     else

     {

         dir.mkpath("/home/pi/hello");

     }


}



댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글