본문 바로가기

프로그래밍105

[Qt] QList에 있는 구조체 정렬하는 방법 (Sort, Struct) QList안에 있는 구조체 아이템의 항목을 기준으로 아이템을 정렬할 수 있어요. ○ 헤더 #include // qDebug() 출력을 위해 추가 struct People { QString Name; int Age; }; void ShowList(QList list);// QList 내용 출력 용도 ○ 메인 void MainWindow::ShowList(QList list) { foreach (People people, list) { qDebug() setupUi(this); // 사람 정보 추가 QList peopleList; peopleList.append(People {"Ghi", 10}); peopleList.append(People {"Def", 30}); peopleList.append(Peop.. 2021. 5. 15.
[Qt] QMessageBox로 알림, 아이콘, 선택 메시지 박스 띄우는 방법 ○ 헤더 및 함수 사용 방법 Header: #include qmake: QT += widgets QMessageBox(QWidget *parent = Q_NULLPTR) QMessageBox(Icon icon, const QString &title, const QString &text, StandardButtons buttons = NoButton, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint) ○ 일반 메시지 박스 #include QMessageBox msgBox; msgBox.setText("setText"); msgBox.exec(); ○ 메시지 박스 아이콘 표시 #inclu.. 2021. 5. 15.
[Linux, C++] 파일 존재, 읽기, 쓰기, 실행 권한 여부 확인하는 방법 (access) access()를 이용하여 해당하는 파일이 있나, 읽기, 쓰기 실행을 할 수 있는지 알 수 있어요. ○ 헤더 및 함수 #include // *pathname : 파일 경로 // mode : 파일에 대한 확인 모드 (F_OK, R_OK, W_OK, X_OK) int access(const char *pathname, int mode); ○ 리턴값 0 : 성공 (파일 있음, 접근 가능) -1 : 실패 (파일 없음, 접근 권한 없음) ○ 예제 #include const char* file = "/home/ubuntu/test.mp4"; if (access(file, F_OK) == 0) { } if (access(file, R_OK) == 0) { } 2021. 5. 15.
[Linux, C++] 파일 소유자, 파일 크기, 접근/수정 시간 등 파일 정보 보는 방법 ○ 헤더 및 함수 #include #include #include int stat(const char *pathname, struct stat *statbuf); int fstat(int fd, struct stat *statbuf); int lstat(const char *pathname, struct stat *statbuf); - 리턴 값 0 : 성공 -1 : 에러 On success, zero is returned. On error, -1 is returned, and errno is set appropriately. ○ stat 구조체 설명 struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* Inode n.. 2021. 5. 15.