본문 바로가기

프로그래밍/기타41

[Qt] 네트워크 인터페이스 IP 가져오는 방법 (자기 IP 알아내기, QNetworkInterface) ○ 필요 헤더 #include #include ○ 네트워크 인터페이스 전체 주소 가져오기 QList addrList = QNetworkInterface::allAddresses(); ○ 네트워크 인터페이스 전체 주소 중 IPv4 주소만 출력하기 #include #include #include // 디버그 출력용 QList addrList = QNetworkInterface::allAddresses(); foreach(QHostAddress addr, addrList) { if (0 < addr.toIPv4Address()) { qDebug() 2021. 5. 15.
[Qt] 파일 존재 여부 확인, 복사, 삭제하는 방법 (QFile) QFile를 이용하여 간단하게 파일 존재 여부, 복사, 삭제 등을 할 수 있어요. ○ 헤더 #include ○ 파일 존재 여부 확인 bool QFile::exists() const bool result = QFile::exists(file); ○ 파일 복사 bool QFile::copy(const QString &newName) bool result = QFile::copy(file, copy_file); ○ 파일 삭제 [static] bool QFile::remove(const QString &fileName) bool result = QFile::remove(FilePath); ○ 사용 예제 (파일 확인 후 복사, 삭제) #include QString file = "/home/ubuntu/test.m.. 2021. 5. 15.
[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.