Logo ROOT   6.16/01
Reference Guide
QtMultiFileDialog.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This is a small ROOT macro to use Qt 3.3 class :[QFileDialog](https://doc.qt.io/archives/3.3/qfiledialog.html)
4/// See: [https://doc.qt.io/archives/3.3/qfiledialog.html#getOpenFileNames](https://doc.qt.io/archives/3.3/qfiledialog.html#getOpenFileNames)
5///
6/// To use, invoke ACLiC from the ROOT prompt:
7/// ~~~
8/// root [] .x QtMultiFileDialog.C++
9/// ~~~
10///
11/// To use it with no ACLiC, omit the trailing "++"
12/// ~~~
13/// root [] .x QtMultiFileDialog.C
14/// ~~~
15///
16/// The QtMultiFileDialog creates TList of TObjString objects and
17/// returns its pointer.
18///
19/// The "QtFileDialog.C" macro provides the simplified version of the "QtMultiFileDialog.C"
20///
21/// Option: you can change the look and feel of the Qt file dialog
22/// by providing the optional parameter "style":
23/// The number of the available styles is defined by your local
24/// Qt installation.
25/// Try: "windows", "motif", "kde", "platinum" etc
26///
27/// The full list of the Qt classes available from Cint is defined by
28/// [by $ROOTSYS/cint/lib/qtclasses.h](http://root.bnl.gov/QtRoot/htmldoc/src/qtclasses.h.html)
29///
30/// All Qt classes can be used from ACLiC though.
31///
32/// \macro_code
33///
34/// \author Valeri Fine 23/03/2006
35
36# include <QApplication>
37# include <QStyle>
38# include <QFileDialog>
39# include <QStringList>
40# include <QString>
41# include "TObjString.h"
42# include "TList.h"
43# include <string>
44
45TList *QtMultiFileDialog(const char *style="") {
46
47 QStyle *saveStyle = 0;
48 if (!QString(style).isEmpty()) {
49 saveStyle = QApplication::style();
50 QApplication::setStyle(style);
51 }
52 TList *listOfNames = new TList();
53 QStringList files = QFileDialog::getOpenFileNames ();
54 QStringList::Iterator it = files.begin();
55 while ( it != files.end() ) {
56 std::string flnm = (*it).toStdString();
57 printf ("Next file selected: %s\n", flnm.c_str() );
58 // Convert QString to TObjString and add it to the output
59 listOfNames->Add(new TObjString(flnm.c_str()));
60 ++it;
61 }
62 // Restore the style
63 if (saveStyle) QApplication::setStyle(saveStyle);
64 printf ("\nThe TList of the file names contains:");
65 printf ("\n-------------------------------------\n");
66 listOfNames->ls();
67 return listOfNames;
68}
virtual void ls(Option_t *option="") const
List (ls) all objects in this collection.
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
Collectable string class.
Definition: TObjString.h:28
TCanvas * style()
Definition: style.C:1