Results 1 to 8 of 8

Thread: Problem with filter in Qdialog

  1. #1

    Default Problem with filter in Qdialog

    Well, my problem is I only want to see the directories that are writeable and save the path of the selected one in a QString


    I have the next code but I dont know how to apply exactly the filter.

    Qt Code:
    1. QString directoryName = QFileDialog::getExistingDirectory(
    2. this,tr("Select directory"),
    3. "/home/"
    4. "QDir::Writable");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with filter in Qdialog

    The static convenience function can't do that.
    You need an explicit instance.

    Cheers,
    _

  3. #3

    Default Re: Problem with filter in Qdialog

    I thougth about that then I have that code too

    Qt Code:
    1. QString directoryName = "";
    2. QFileDialog explorador;
    3. explorador.getExistingDirectory(this);
    4. explorador.setFilter(QDir::Writable);
    5. explorador.tr("Select a directory");
    6. explorador.directory("/home");
    To copy to clipboard, switch view to plain text mode 

    Also I think code is wrong xD
    And then the problem is how do I save the path of the selected directory????
    Last edited by Spinter; 2nd December 2014 at 12:23.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with filter in Qdialog

    Quote Originally Posted by Spinter View Post
    I thougth about that then I have that code too

    Qt Code:
    1. QString directoryName = "";
    2. QFileDialog explorador;
    3. explorador.getExistingDirectory(this);
    4. explorador.setFilter(QDir::Writable);
    5. explorador.tr("Select a directory");
    6. explorador.directory("/home");
    To copy to clipboard, switch view to plain text mode 

    Also I think code is wrong xD
    And then the problem is how do I save the path of the selected directory????
    But this code does not make sense. In line 3 You are calling static method without saving the result.
    First You should set all parameters and then do something like this :
    Qt Code:
    1. QStringList fileNames;
    2. if (dialog.exec())
    3. fileNames = dialog.selectedFiles();
    To copy to clipboard, switch view to plain text mode 
    All of this is shown here

  5. #5

    Default Re: Problem with filter in Qdialog

    Well I do it in that way but I am still having the same error

    Qt Code:
    1. QString directoryName = "";
    2. QFileDialog *explorador = new QFileDialog(this);
    3. explorador->setFileMode(QFileDialog::DirectoryOnly);
    4. explorador->setFilter(QDir::Writable);
    5. explorador->setWindowTitle(QFileDialog::tr("Select a folder"));
    6. explorador->setDirectory(QFileDialog::tr("/home"));
    7. explorador->exec();
    8. directoryName = explorador->selectedFiles().front();
    To copy to clipboard, switch view to plain text mode 

    The error is that I am still able to select folders where normal users (not superuser) aren't allow to write.

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with filter in Qdialog

    Read once more doc for QDir::Filters.

  7. #7

    Default Re: Problem with filter in Qdialog

    Yes I read it but then it is no possible to select directories that cant be writeable by normal users with filters???, I mean if writeable list files, how I list directories???.

    I dont get it.

    you need to use QDir:irs after the first filter???

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with filter in Qdialog

    I think You don't read... From the doc of value QDir::Writable List files for which the application has write access. The Writable value needs to be combined with Dirs or Files.
    So You should use it like this
    Qt Code:
    1. explorador->setFilter(QDir::Writable | QDir::QDir::Dirs);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QDialog problem
    By bostero22 in forum Newbie
    Replies: 6
    Last Post: 27th December 2015, 19:26
  2. problem with event filter compile for S60
    By jimiq in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 6th July 2010, 20:48
  3. Event Filter & No Focus problem
    By AlexanderPopov in forum Newbie
    Replies: 0
    Last Post: 22nd December 2009, 21:15
  4. Problem with QDialog
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 2nd December 2009, 13:26
  5. Q3Table event filter problem
    By batileon in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 11:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.