PDA

View Full Version : set enable QPushButton doesn't work.



HelloDan
4th March 2009, 15:26
FileFilter::FileFilter(QWidget *parent):QDialog(parent)
{

setupUi(this);
// Disable relative buttons
loadButton->setEnabled(false);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

//connect signals and slots
connect(browseButton,SIGNAL(clicked()),this,SLOT(b rowse()));
connect(selectButton,SIGNAL(clicked()),this,SLOT(s elect()));
// connect(loadButton,SIGNAL(clicked()),this,SLOT(loa d()));
// connect(buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),thi s,SLOT(deleteInDir()));
connect(fileTypeComboBox,SIGNAL(currentIndexChange d(int index)), this, SLOT(textChanged()));
connect(deletedDirComboBox,SIGNAL(currentIndexChan ged(int index)), this, SLOT(textChanged()));
connect(sourceDirComboBox,SIGNAL(currentIndexChang ed(int index)), this, SLOT(textChanged()));
}



// if all the file input directory have been configured, enable OK and button.
void FileFilter::textChanged()
{
buttonBox->button(QDialogButtonBox::Ok)->setEnabled((!(sourceDirComboBox->currentText()).isEmpty())&&(!(deletedDirComboBox->currentText()).isEmpty())&&(!(fileTypeComboBox->currentText()).isEmpty()));
loadButton->setEnabled((!(sourceDirComboBox->currentText()).isEmpty())&&(!(deletedDirComboBox->currentText()).isEmpty())&&(!(fileTypeComboBox->currentText()).isEmpty()));
}



void FileFilter::browse()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Select a directory"), QDir::currentPath());
if (!directory.isEmpty())
{
sourceDirComboBox->addItem(QDir::toNativeSeparators(directory));
sourceDirComboBox->setCurrentIndex(sourceDirComboBox->count() - 1);
}
}





// select a dir to delete files from it
void FileFilter::select()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Select directory"), QDir::currentPath());
if (!directory.isEmpty())
{
deletedDirComboBox->addItem(QDir::toNativeSeparators(directory));
deletedDirComboBox->setCurrentIndex(deletedDirComboBox->count() - 1);
}
}



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!

HelloDan
4th March 2009, 15:31
I also tried void QComboBox::editTextChanged ( const QString & text ) [signal] instead of currentIndexChanged(int index), but failed too.

HelloDan
4th March 2009, 16:15
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


for(int i = 0; i < files.size(); ++i)
{
QFile file(currentDir.absoluteFilePath(files[i]));
qint64 size = QFileInfo(file).size();

QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
.arg(int((size + 1023) / 1024)));
sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);

int row = filesTable->rowCount();
filesTable->insertRow(row);
filesTable->setItem(row, 0, fileNameItem);
filesTable->setItem(row, 1, sizeItem);
}


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

aamer4yu
4th March 2009, 16:59
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()));

HelloDan
4th March 2009, 17:40
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

HelloDan
5th March 2009, 01:31
the problem had been solved.
QDir currentDir = QDir(sourcePath); I make it a local variable.

Thanks for you attention!