2011-11-22 4 views
0

파일 또는 폴더를 선택하기 위해 Qt에서 단 하나의 대화 상자를 사용하는 방법이 있습니까?폴더 또는 파일 선택

나는 옵션을 갖고 싶습니다. 선택을하고,이 사용자를 사용하여 같은 대화 상자에서 폴더 나 파일을 선택할 수 있습니다.

+0

그렇지 않은 것으로 보입니다. 자신의 파일 대화 상자 클래스를 작성하는 것은 어떻습니까? 그렇지 않다면 두 개의 다른 동작을 사용합니다. 하나는 파일 용이고 다른 하나는 디렉토리 용입니다. – zebrilo

+0

@zebrilo ok 충분히 좋습니다. 자신의 파일 대화 상자 클래스가 갈 수있는 방법 일 수 있습니다. 감사 – smallB

답변

0

내장 된 위젯은 없지만 QDirModel을 QTreeView에 연결하고 선택 신호를받는 것은 쉽습니다. 여기

당신이 시작하는 예입니다

Test.cpp에

#include <QtGui> 

#include "print.h" 

int main(int argc, char** argv) 
{ 
    QApplication app(argc, argv); 

    QDirModel mdl; 
    QTreeView view; 
    Print print(&mdl); 

    view.setModel(&mdl); 
    QObject::connect(
     view.selectionModel(), 
     SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), 
     &print, 
     SLOT(currentChanged(const QModelIndex&,const QModelIndex&))); 
    view.show(); 

    return app.exec(); 
} 

print.h

#ifndef _PRINT_H_ 
#define _PRINT_H_ 
#include <QtGui> 

class Print : public QObject 
{ 
    Q_OBJECT 
    public: 
     Print(QDirModel* mdl); 
     ~Print(); 
    public slots: 
     void currentChanged(const QModelIndex& current, const QModelIndex&); 
    private: 
     QDirModel* mModel; 
     Q_DISABLE_COPY(Print) 
}; 

#endif 

print.cpp

#include "print.h" 

Print::Print(QDirModel* mdl) : QObject(0), mModel(mdl) {} 
Print::~Print() {} 

void Print::currentChanged(const QModelIndex& current, const QModelIndex&) 
{ 
    qDebug() << mModel->filePath(current); 
}