[solved]QFileDialog -> QDirectoryDialog
[solved]QFileDialog -> QDirectoryDialog
Hallo,
ich kann per Menüführung mit QFileDialog (File->Open) Files öffnen!
Jetzt möchte ich aber nur ein Verzeichnis öffnen und musste feststellen, dass es kein QDirectoryDialog gibt?
Gibts ne einfache Lsg zu dem Problem?
ich kann per Menüführung mit QFileDialog (File->Open) Files öffnen!
Jetzt möchte ich aber nur ein Verzeichnis öffnen und musste feststellen, dass es kein QDirectoryDialog gibt?
Gibts ne einfache Lsg zu dem Problem?
Zuletzt geändert von AndiLatte am 17. Januar 2008 16:29, insgesamt 3-mal geändert.
Ganz schwer zu finden:
Code: Alles auswählen
QString QFileDialog::getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly ) 8)upsala hat geschrieben:Ganz schwer zu finden:Code: Alles auswählen
QString QFileDialog::getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = ShowDirsOnly )
-
-=Freaky=-
- Beiträge: 503
- Registriert: 29. Dezember 2006 22:54
- Wohnort: HL
Code: Alles auswählen
QString chosenDir = QFileDialog::getExistingDirectory( 0, "Chose a directory." );
if( chosenDir.isEmpty() )
// kein verzeichnis gewaehlt (abgebrochen)
else
// verzeichnisname steht in chosenDir, mach damit was du willst. ;)julian
na sowas hatte ich mir auch ausgemalt.-=Freaky=- hat geschrieben:Code: Alles auswählen
QString chosenDir = QFileDialog::getExistingDirectory( 0, "Chose a directory." ); if( chosenDir.isEmpty() ) // kein verzeichnis gewaehlt (abgebrochen) else // verzeichnisname steht in chosenDir, mach damit was du willst. ;)
aber der compiler mag kein
Code: Alles auswählen
QString chosenDir = QFileDialog::getExistingDirectory( 0, "Chose a directory." );
std::cout << "Ordner: " << chosenDir << std::end;Wenn Du es schon nicht selber siehst, sollte dir wenigstens der Compiler sagen was er nicht mag. Außerdem gibt es qDebug für sowas.AndiLatte hat geschrieben:aber der compiler mag keinCode: Alles auswählen
QString chosenDir = QFileDialog::getExistingDirectory( 0, "Chose a directory." ); std::cout << "Ordner: " << chosenDir << std::end;
Die deutsche Schriftsprache ist case-sensitive. Außerdem gibt es eine Interpunktionsnorm. Wenn manch einer seine Programme genauso schlampig schreibt, wie sein Posting hier, dann sollte er es lieber bleiben lassen.
Der Compiler sagt hierzu
folgendes:
Code: Alles auswählen
include <iostream>
void MainWindow::open()
{
// QString directoryName = QDirectoryDialog::getOpenFileName(this, tr("Open MIDIAS Data"),currentDataDirectory);
QString directoryName = QFileDialog::getExistingDirectory(this, tr("Please choose MIDIAS Data"));
if(!directoryName.isEmpty())
openDirectory(directoryName);
std::cout << directoryName << std::endl;
}folgendes:
Code: Alles auswählen
make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include/QtOpenGL -I/usr/include/QtOpenGL -I/usr/include -I. -I/usr/X11R6/include -I. -I. -o mainwindow.o mainwindow.cpp
mainwindow.cpp: In member function ‘void MainWindow::open()’:
mainwindow.cpp:237: error: no match for ‘operator<<’ in ‘std::cout << directoryName’
/usr/include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:78: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:90: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:241: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:264: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:102: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:125: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:157: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:183: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:215: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:288: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:311: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:361: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:335: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:384: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:407: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/bits/ostream.tcc:430: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/QtCore/qchar.h:293: note: QDataStream& operator<<(QDataStream&, const QChar&)
/usr/include/QtCore/qbytearray.h:509: note: QDataStream& operator<<(QDataStream&, const QByteArray&)
/usr/include/QtCore/qstring.h:899: note: QDataStream& operator<<(QDataStream&, const QString&)
/usr/include/QtCore/qobject.h:416: note: QDebug operator<<(QDebug, const QObject*)
/usr/include/QtCore/qiodevice.h:225: note: QDebug operator<<(QDebug, QFlags<QIODevice::OpenModeFlag>)
/usr/include/QtCore/qtextstream.h:265: note: QTextStream& operator<<(QTextStream&, QTextStream& (*)(QTextStream&))
/usr/include/QtCore/qtextstream.h:268: note: QTextStream& operator<<(QTextStream&, QTextStreamManipulator)
/usr/include/QtCore/qregexp.h:121: note: QDataStream& operator<<(QDataStream&, const QRegExp&)
/usr/include/QtCore/qstringlist.h:208: note: QDataStream& operator<<(QDataStream&, const QStringList&)
/usr/include/QtCore/qlocale.h:529: note: QDataStream& operator<<(QDataStream&, const QLocale&)
/usr/include/QtCore/qurl.h:227: note: QDataStream& operator<<(QDataStream&, const QUrl&)
/usr/include/QtCore/qurl.h:232: note: QDebug operator<<(QDebug, const QUrl&)
/usr/include/QtCore/qvariant.h:562: note: QDebug operator<<(QDebug, const QVariant&)
/usr/include/QtCore/qvariant.h:468: note: QDataStream& operator<<(QDataStream&, const QVariant&)
/usr/include/QtCore/qvariant.h:470: note: QDataStream& operator<<(QDataStream&, QVariant::Type)
/usr/include/QtCore/qvariant.h:563: note: QDebug operator<<(QDebug, QVariant::Type)
/usr/include/QtCore/qpoint.h:82: note: QDataStream& operator<<(QDataStream&, const QPoint&)
/usr/include/QtCore/qpoint.h:162: note: QDebug operator<<(QDebug, const QPoint&)
/usr/include/QtCore/qpoint.h:215: note: QDataStream& operator<<(QDataStream&, const QPointF&)
/usr/include/QtCore/qpoint.h:336: note: QDebug operator<<(QDebug, const QPointF&)
/usr/include/QtCore/qline.h:141: note: QDebug operator<<(QDebug, const QLine&)
/usr/include/QtCore/qline.h:145: note: QDataStream& operator<<(QDataStream&, const QLine&)
/usr/include/QtCore/qline.h:301: note: QDebug operator<<(QDebug, const QLineF&)
/usr/include/QtCore/qline.h:305: note: QDataStream& operator<<(QDataStream&, const QLineF&)
/usr/include/QtCore/qsize.h:81: note: QDataStream& operator<<(QDataStream&, const QSize&)
/usr/include/QtCore/qsize.h:176: note: QDebug operator<<(QDebug, const QSize&)
/usr/include/QtCore/qsize.h:232: note: QDataStream& operator<<(QDataStream&, const QSizeF&)
/usr/include/QtCore/qsize.h:337: note: QDebug operator<<(QDebug, const QSizeF&)
/usr/include/QtCore/qrect.h:178: note: QDataStream& operator<<(QDataStream&, const QRect&)
/usr/include/QtCore/qrect.h:486: note: QDebug operator<<(QDebug, const QRect&)
/usr/include/QtCore/qrect.h:598: note: QDataStream& operator<<(QDataStream&, const QRectF&)
/usr/include/QtCore/qrect.h:820: note: QDebug operator<<(QDebug, const QRectF&)
/usr/include/QtCore/qbitarray.h:138: note: QDataStream& operator<<(QDataStream&, const QBitArray&)
/usr/include/QtCore/qdatetime.h:273: note: QDataStream& operator<<(QDataStream&, const QDate&)
/usr/include/QtCore/qdatetime.h:275: note: QDataStream& operator<<(QDataStream&, const QTime&)
/usr/include/QtCore/qdatetime.h:277: note: QDataStream& operator<<(QDataStream&, const QDateTime&)
/usr/include/QtCore/qdatetime.h:282: note: QDebug operator<<(QDebug, const QDate&)
/usr/include/QtCore/qdatetime.h:283: note: QDebug operator<<(QDebug, const QTime&)
/usr/include/QtCore/qdatetime.h:284: note: QDebug operator<<(QDebug, const QDateTime&)
/usr/include/QtCore/qabstractitemmodel.h:75: note: QDebug operator<<(QDebug, const QModelIndex&)
/usr/include/QtCore/qabstractitemmodel.h:116: note: QDebug operator<<(QDebug, const QPersistentModelIndex&)
/usr/include/QtCore/quuid.h:160: note: QDataStream& operator<<(QDataStream&, const QUuid&)
/usr/include/QtGui/qcolor.h:40: note: QDebug operator<<(QDebug, const QColor&)
/usr/include/QtGui/qcolor.h:214: note: QDataStream& operator<<(QDataStream&, const QColor&)
/usr/include/QtGui/qfont.h:265: note: QDataStream& operator<<(QDataStream&, const QFont&)
/usr/include/QtGui/qpen.h:94: note: QDataStream& operator<<(QDataStream&, const QPen&)
/usr/include/QtGui/qpen.h:103: note: QDebug operator<<(QDebug, const QPen&)
/usr/include/QtGui/qpolygon.h:69: note: QDebug operator<<(QDebug, const QPolygon&)
/usr/include/QtGui/qpolygon.h:114: note: QDebug operator<<(QDebug, const QPolygonF&)
/usr/include/QtGui/qpolygon.h:121: note: QDataStream& operator<<(QDataStream&, const QPolygonF&)
/usr/include/QtGui/qregion.h:168: note: QDataStream& operator<<(QDataStream&, const QRegion&)
/usr/include/QtGui/qregion.h:173: note: QDebug operator<<(QDebug, const QRegion&)
/usr/include/QtGui/qmatrix.h:137: note: QDataStream& operator<<(QDataStream&, const QMatrix&)
/usr/include/QtGui/qmatrix.h:141: note: QDebug operator<<(QDebug, const QMatrix&)
/usr/include/QtGui/qimage.h:304: note: QDataStream& operator<<(QDataStream&, const QImage&)
/usr/include/QtGui/qpixmap.h:245: note: QDataStream& operator<<(QDataStream&, const QPixmap&)
/usr/include/QtGui/qbrush.h:115: note: QDataStream& operator<<(QDataStream&, const QBrush&)
/usr/include/QtGui/qbrush.h:120: note: QDebug operator<<(QDebug, const QBrush&)
/usr/include/QtGui/qtextformat.h:93: note: QDataStream& operator<<(QDataStream&, const QTextLength&)
/usr/include/QtGui/qtextformat.h:300: note: QDataStream& operator<<(QDataStream&, const QTextFormat&)
/usr/include/QtGui/qkeysequence.h:172: note: QDataStream& operator<<(QDataStream&, const QKeySequence&)
/usr/include/QtGui/qkeysequence.h:182: note: QDebug operator<<(QDebug, const QKeySequence&)
/usr/include/QtGui/qevent.h:684: note: QDebug operator<<(QDebug, const QEvent*)
/usr/include/QtGui/qpalette.h:219: note: QDataStream& operator<<(QDataStream&, const QPalette&)
/usr/include/QtGui/qsizepolicy.h:154: note: QDataStream& operator<<(QDataStream&, const QSizePolicy&)
/usr/include/QtGui/qcursor.h:131: note: QDataStream& operator<<(QDataStream&, const QCursor&)
/usr/include/QtGui/qitemselectionmodel.h:200: note: QDebug operator<<(QDebug, const QItemSelectionRange&)
/usr/include/QtGui/qicon.h:100: note: QDataStream& operator<<(QDataStream&, const QIcon&)
/usr/include/QtGui/qpicture.h:161: note: QDataStream& operator<<(QDataStream&, const QPicture&)
/usr/include/QtGui/qpainterpath.h:175: note: QDataStream& operator<<(QDataStream&, const QPainterPath&)
/usr/include/QtGui/qlistwidget.h:174: note: QDataStream& operator<<(QDataStream&, const QListWidgetItem&)
/usr/include/QtGui/qstandarditemmodel.h:414: note: QDataStream& operator<<(QDataStream&, const QStandardItem&)
/usr/include/QtGui/qtablewidget.h:193: note: QDataStream& operator<<(QDataStream&, const QTableWidgetItem&)
/usr/include/QtGui/qtreewidget.h:218: note: QDataStream& operator<<(QDataStream&, const QTreeWidgetItem&)
/usr/include/QtGui/qgraphicsitem.h:738: note: QDebug operator<<(QDebug, QGraphicsItem*)
/usr/include/QtGui/qsplitter.h:132: note: QTextStream& operator<<(QTextStream&, const QSplitter&)-
-=Freaky=-
- Beiträge: 503
- Registriert: 29. Dezember 2006 22:54
- Wohnort: HL
doku hilft:
nebenbei waer qDebug wirklich passender hier.
mfg,
julian
Code: Alles auswählen
std::cout << chosenDir.toStdString() << std::endl;mfg,
julian
Du brauchst nicht die ganzen Compiler Ausgaben posten. Meist reicht der Anfang, der Rest sind Folgefehler.
Was steht da? Er hat keinen Operator gefunden, der einen QString für cout konvertiert. Also musst Du den QString selbst passend konvertieren, z.B. mit
directoryName.toAscii()
Das sollte man aber auch eigentlich wissen, das das nicht gehen konnte. Ich würde trotzdem qDebug nehmen.
qDebug() << directoryName;
Code: Alles auswählen
mainwindow.cpp:237: error: no match for ‘operator<<’ in ‘std::cout << directoryName’ directoryName.toAscii()
Das sollte man aber auch eigentlich wissen, das das nicht gehen konnte. Ich würde trotzdem qDebug nehmen.
qDebug() << directoryName;
Die deutsche Schriftsprache ist case-sensitive. Außerdem gibt es eine Interpunktionsnorm. Wenn manch einer seine Programme genauso schlampig schreibt, wie sein Posting hier, dann sollte er es lieber bleiben lassen.