Results 1 to 6 of 6

Thread: set enable QPushButton doesn't work.

  1. #1
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default set enable QPushButton doesn't work.

    Qt Code:
    1. FileFilter::FileFilter(QWidget *parent):QDialog(parent)
    2. {
    3.  
    4. setupUi(this);
    5. // Disable relative buttons
    6. loadButton->setEnabled(false);
    7. buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
    8.  
    9. //connect signals and slots
    10. connect(browseButton,SIGNAL(clicked()),this,SLOT(browse()));
    11. connect(selectButton,SIGNAL(clicked()),this,SLOT(select()));
    12. // connect(loadButton,SIGNAL(clicked()),this,SLOT(load()));
    13. // connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(deleteInDir()));
    14. connect(fileTypeComboBox,SIGNAL(currentIndexChanged(int index)), this, SLOT(textChanged()));
    15. connect(deletedDirComboBox,SIGNAL(currentIndexChanged(int index)), this, SLOT(textChanged()));
    16. connect(sourceDirComboBox,SIGNAL(currentIndexChanged(int index)), this, SLOT(textChanged()));
    17. }
    18.  
    19.  
    20.  
    21. // if all the file input directory have been configured, enable OK and button.
    22. void FileFilter::textChanged()
    23. {
    24. buttonBox->button(QDialogButtonBox::Ok)->setEnabled((!(sourceDirComboBox->currentText()).isEmpty())&&(!(deletedDirComboBox->currentText()).isEmpty())&&(!(fileTypeComboBox->currentText()).isEmpty()));
    25. loadButton->setEnabled((!(sourceDirComboBox->currentText()).isEmpty())&&(!(deletedDirComboBox->currentText()).isEmpty())&&(!(fileTypeComboBox->currentText()).isEmpty()));
    26. }
    27.  
    28.  
    29.  
    30. void FileFilter::browse()
    31. {
    32. QString directory = QFileDialog::getExistingDirectory(this,
    33. tr("Select a directory"), QDir::currentPath());
    34. if (!directory.isEmpty())
    35. {
    36. sourceDirComboBox->addItem(QDir::toNativeSeparators(directory));
    37. sourceDirComboBox->setCurrentIndex(sourceDirComboBox->count() - 1);
    38. }
    39. }
    40.  
    41.  
    42.  
    43.  
    44.  
    45. // select a dir to delete files from it
    46. void FileFilter::select()
    47. {
    48. QString directory = QFileDialog::getExistingDirectory(this,
    49. tr("Select directory"), QDir::currentPath());
    50. if (!directory.isEmpty())
    51. {
    52. deletedDirComboBox->addItem(QDir::toNativeSeparators(directory));
    53. deletedDirComboBox->setCurrentIndex(deletedDirComboBox->count() - 1);
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 

    Hi my friends! I'm coming for help again.

    In a dialog base app, I use two QFileDialogs to get dirs to store in two comboxs. if the three comboxs are not empty, it will enable the OK and Load buttons, But my code doesen't work. Could you help to find the problem?

    Thanks!

  2. #2
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set enable QPushButton doesn't work.

    I also tried void QComboBox::editTextChanged ( const QString & text ) [signal] instead of currentIndexChanged(int index), but failed too.

  3. #3
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set enable QPushButton doesn't work.

    I come to know that, the complier tell me.

    No such signal QComboBox::currentIndexChanged(int index) in filefilter.cpp:22


    But that does have a QComboBox::currentIndexChanged(int index) signal. Why?

    By the way, the following segment code is just copy from the demo
    Qt Code:
    1. for(int i = 0; i < files.size(); ++i)
    2. {
    3. QFile file(currentDir.absoluteFilePath(files[i]));
    4. qint64 size = QFileInfo(file).size();
    5.  
    6. QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
    7. fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
    8. QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
    9. .arg(int((size + 1023) / 1024)));
    10. sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
    11. sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
    12.  
    13. int row = filesTable->rowCount();
    14. filesTable->insertRow(row);
    15. filesTable->setItem(row, 0, fileNameItem);
    16. filesTable->setItem(row, 1, sizeItem);
    17. }
    To copy to clipboard, switch view to plain text mode 

    But why the size show in cells are 0. The files are MP3, Their sizes are not zero.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: set enable QPushButton doesn't work.

    You are not supposed to give name of data type in connect..
    ie.
    connect(fileTypeComboBox,SIGNAL(currentIndexChange d(int index)), this, SLOT(textChanged()));
    should be
    connect(fileTypeComboBox,SIGNAL(currentIndexChange d(int)), this, SLOT(textChanged()));

  5. The following user says thank you to aamer4yu for this useful post:

    HelloDan (4th March 2009)

  6. #5
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set enable QPushButton doesn't work.

    Quote Originally Posted by aamer4yu View Post
    You are not supposed to give name of data type in connect..
    ie.
    should be
    What about the zero file size? I copy the code from the demo

  7. #6
    Join Date
    Feb 2009
    Location
    Guangzhou,China
    Posts
    89
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: set enable QPushButton doesn't work.

    the problem had been solved.
    QDir currentDir = QDir(sourcePath); I make it a local variable.

    Thanks for you attention!

Similar Threads

  1. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  2. Replies: 3
    Last Post: 26th September 2006, 12:16

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.