[Interest] QDirIterator as Variable in class
Hello I want to iterate trough a directory one step at a time. Driven by signals. So after each signal I want to do another step. I have createt the following class in which I try to create a variable of the type of QDirIterator. This however fails with the message no matching function for call to 0QDirIterator::QDirIterator()' in the constructor. If I comment out the mediaItr variable declaration, it works without error. So what is it I'm doing wrong? A assume its something due to my .NET background so I don't see the whole cpp scope yet. Class.h: class MediaBase : public QObject { Q_OBJECT QObject *player; QDir mediaDir; QDirIterator mediaItr; public: explicit MediaBase(QObject *parent = 0); void setPlayer (QObject *player = 0); void setMediaDir (QString path); private: QVariant getNext(); signals: public slots: void movieStopped() { if (player!=NULL) player-setProperty(thesource, getNext()); } }; Class.cpp: MediaBase::MediaBase(QObject *parent) : QObject(parent) { QDirIterator mediaItr(); } void MediaBase::setPlayer(QObject *player) { this-player = player; } void MediaBase::setMediaDir (QString path) { mediaDir = QDir(path); if (mediaDir.exists()){ //this-mediaItr = QDirIterator(mediaDir); } else qDebug() could not load mediaDir endl; } QVariant MediaBase::getNext(){ return QVariant(); } Freundliche Grüsse / Best Regards / Meilleures salutations Adrian Stern Diese E-Mail und ihre Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail inklusive Anhänge. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der Inhalte dieser Mail ist nicht gestattet. This e-mail and any attachments may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail including the attachments. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] QDirIterator as Variable in class
Il 23/04/2013 14:12, Adrian Stern ha scritto: MediaBase::MediaBase(QObject *parent) : QObject(parent) { Error 1, straight from the compiler: since you're not calling a QDirIterator constructor in your constructor's initializer list for the mediaItr data member variable, the compiler calls the default constructor. But QDirIterator lacks a default constructor. Therefore, you got an error QDirIterator mediaItr(); Error 2, much more subtle: this is declaring a function called mediaItr, taking no arguments, returning a QDirIterator, and shadowing the member variable of the same name. (Yes, it's the C++ most vexing parse.) I know why you did this, but this is nonsense. Just remove it. Note: I'm deliberately NOT writing the solution because I'd like to encourage you to search the web for all the keywords I used (initializer list, member, default constructor, most vexing parse). This is a C++ problem, not a Qt one. HTH, -- Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Software Engineer KDAB (UK) Ltd., a KDAB Group company Tel. UK +44-1738-450410, Sweden (HQ) +46-563-540090 KDAB - Qt Experts - Platform-independent software solutions ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest