How to use the QCommandLineParser
-
I am trying to create a file tree of tableview using QCommandLineParser.
I've seen the example provided by Qt, but I'm new to QCommandLineParser and I'm not familiar with it, so I'm asking. How can I see only the folder on the D drive instead of the whole directory?
- Example
int main(int argc, char *argv[]) { QApplication app(argc, argv); QCoreApplication::setApplicationVersion(QT_VERSION_STR); QCommandLineParser parser; parser.setApplicationDescription("Qt Dir View Example"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons"); parser.addOption(dontUseCustomDirectoryIconsOption); QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch"); parser.addOption(dontWatchOption); parser.addPositionalArgument("directory", "The directory to start in."); parser.process(app); const QString rootPath = parser.positionalArguments().isEmpty() ? QString() : parser.positionalArguments().first(); QFileSystemModel model; model.setRootPath(""); if (parser.isSet(dontUseCustomDirectoryIconsOption)) model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons); if (parser.isSet(dontWatchOption)) model.setOption(QFileSystemModel::DontWatchForChanges); QTreeView tree; tree.setModel(&model); if (!rootPath.isEmpty()) { const QModelIndex rootIndex = model.index(QDir::cleanPath(rootPath)); if (rootIndex.isValid()) tree.setRootIndex(rootIndex); } // Demonstrating look and feel features tree.setAnimated(false); tree.setIndentation(40); // 들여쓰기 위치 tree.setSortingEnabled(true); // 정렬 여부 const QSize availableSize = tree.screen()->availableGeometry().size(); tree.resize(availableSize / 2); tree.setColumnWidth(0, tree.width() / 3); // Make it flickable on touchscreens QScroller::grabGesture(&tree, QScroller::TouchGesture); tree.setWindowTitle(QObject::tr("Dir View")); tree.show(); return app.exec(); }
-
foreach(QFileInfo info, QDir::drives()) { QEventLoop loop; QObject::connect(m_pDirModel, &QFileSystemModel::directoryLoaded, &loop, &QEventLoop::quit); qDebug() << "fileName : " << info.fileName(); qDebug() << "absoluteFilePath : " << info.absoluteFilePath(); qDebug() << "filePath : " << info.filePath(); qDebug() << "absoluteDir : " << info.absoluteDir(); qDebug() << "absolutePath : " << info.absolutePath(); // 읽을 디렉토리 설정 m_pDirModel->setRootPath(info.filePath()); //m_pDirModel->setRootPath("D:/yhJeong_Doc/"); loop.exec(); } this->ui.treeView->setModel(m_pDirModel); this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest"));
this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest"));
this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest")); It is solved by setting the path.
-
I am trying to create a file tree of tableview using QCommandLineParser.
I've seen the example provided by Qt, but I'm new to QCommandLineParser and I'm not familiar with it, so I'm asking. How can I see only the folder on the D drive instead of the whole directory?
- Example
int main(int argc, char *argv[]) { QApplication app(argc, argv); QCoreApplication::setApplicationVersion(QT_VERSION_STR); QCommandLineParser parser; parser.setApplicationDescription("Qt Dir View Example"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons"); parser.addOption(dontUseCustomDirectoryIconsOption); QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch"); parser.addOption(dontWatchOption); parser.addPositionalArgument("directory", "The directory to start in."); parser.process(app); const QString rootPath = parser.positionalArguments().isEmpty() ? QString() : parser.positionalArguments().first(); QFileSystemModel model; model.setRootPath(""); if (parser.isSet(dontUseCustomDirectoryIconsOption)) model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons); if (parser.isSet(dontWatchOption)) model.setOption(QFileSystemModel::DontWatchForChanges); QTreeView tree; tree.setModel(&model); if (!rootPath.isEmpty()) { const QModelIndex rootIndex = model.index(QDir::cleanPath(rootPath)); if (rootIndex.isValid()) tree.setRootIndex(rootIndex); } // Demonstrating look and feel features tree.setAnimated(false); tree.setIndentation(40); // 들여쓰기 위치 tree.setSortingEnabled(true); // 정렬 여부 const QSize availableSize = tree.screen()->availableGeometry().size(); tree.resize(availableSize / 2); tree.setColumnWidth(0, tree.width() / 3); // Make it flickable on touchscreens QScroller::grabGesture(&tree, QScroller::TouchGesture); tree.setWindowTitle(QObject::tr("Dir View")); tree.show(); return app.exec(); }
@IknowQT said in How to use the QCommandLineParser:
How can I see only the folder on the D drive instead of the whole directory?
What do you mean and how is this related to QCommandLineParser?
What is "whole directory"? Do you mean all folders on drive D? -
@IknowQT said in How to use the QCommandLineParser:
How can I see only the folder on the D drive instead of the whole directory?
What do you mean and how is this related to QCommandLineParser?
What is "whole directory"? Do you mean all folders on drive D?m_pDirModel = new usrFileSystemModel(this); m_pDirModel->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot); foreach(QFileInfo info, QDir::drives()) { QEventLoop loop; QObject::connect(m_pDirModel, &QFileSystemModel::directoryLoaded, &loop, &QEventLoop::quit); // 읽을 디렉토리 설정 m_pDirModel->setRootPath(info.filePath()); loop.exec(); } this->ui.treeView->setModel(m_pDirModel); // [두번째 이후 모든 컬럼 숨김] for (int i = m_pDirModel->columnCount() - 1; i > 0; --i) this->ui.treeView->setColumnHidden(i, true); // [펼치기/감추기 아이콘 숨김] this->ui.treeView->setRootIsDecorated(false); // [헤더 없애기] this->ui.treeView->setHeaderHidden(true); // [폰트 설정] this->ui.treeView->setFont(cGlobalParam::gGetUseMultipleFont(13)); // [행 사이즈 설정] usrItemDelegate* itemdelegate = new usrItemDelegate(this); itemdelegate->SetHeight(60); this->ui.treeView->setItemDelegate(itemdelegate);
Currently, it shows the entire driver.
What I want is to show only the local folder.For example, when there is a path called D:/Test/Source, I want to display only the contents in the Source folder. In a folder called Source, there may be folders and may contain files.
-
@IknowQT said in How to use the QCommandLineParser:
What I want is to show only the local folder.
The documentation has even an example on how to do so: https://doc.qt.io/qt-5/qfilesystemmodel.html#example-usage
Don't know how this is related the QCommandLineParser though.
-
@IknowQT said in How to use the QCommandLineParser:
What I want is to show only the local folder.
The documentation has even an example on how to do so: https://doc.qt.io/qt-5/qfilesystemmodel.html#example-usage
Don't know how this is related the QCommandLineParser though.
m_pDirModel->setRootPath("D:/yhJeong_Doc/");
I did this, but the result is the same.
-
m_pDirModel->setRootPath("D:/yhJeong_Doc/");
I did this, but the result is the same.
@IknowQT said in How to use the QCommandLineParser:
m_pDirModel->setRootPath("D:/yhJeong_Doc/");
Since you say earlier
For example, when there is a path called D:/Test/Source, I want to display only the contents in the Source folder
why do you set the root path to
D:/yhJeong_Doc/
? What do you expect that to do/show? -
foreach(QFileInfo info, QDir::drives()) { QEventLoop loop; QObject::connect(m_pDirModel, &QFileSystemModel::directoryLoaded, &loop, &QEventLoop::quit); qDebug() << "fileName : " << info.fileName(); qDebug() << "absoluteFilePath : " << info.absoluteFilePath(); qDebug() << "filePath : " << info.filePath(); qDebug() << "absoluteDir : " << info.absoluteDir(); qDebug() << "absolutePath : " << info.absolutePath(); // 읽을 디렉토리 설정 m_pDirModel->setRootPath(info.filePath()); //m_pDirModel->setRootPath("D:/yhJeong_Doc/"); loop.exec(); } this->ui.treeView->setModel(m_pDirModel); this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest"));
this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest"));
this->ui.treeView->setRootIndex(m_pDirModel->index("D:/rootTest")); It is solved by setting the path.