Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'operator=' is deprecated: Use QDir::setPath() instead

Tags:

c++

qt5

Simple program that opens a GUI, you click one button to set curDir, click another button to set savDir, and a third button does some C++ code similar to

ls -l curDir > savDir.txt

One of my Qt functions:

void dirList::on_savBut_clicked(){
    savDir = QFileDialog::getExistingDirectory(
                this,"Save Location",QDir::homePath());
    savPath = savDir.absolutePath();
    ui->savText->setText(savPath);
}

On the savDir = QFileDialog::getExistingDirectory(... line I get a warning:

'operator=' is depreciated: Use QDir::setPath() instead

Could anyone give an example how I might incorporate setPath()?

like image 755
Zultor Avatar asked Oct 30 '25 02:10

Zultor


2 Answers

You can simply write

savPath = QFileDialog::getExistingDirectory(
            this,"Save Location",QDir::homePath());

Without using savDir.

like image 53
Doch88 Avatar answered Nov 01 '25 17:11

Doch88


I believe setPath is just a drop in replacement instead of using assignment for when updating a QDir with a QString path.

savDir = QFileDialog::getExistingDirectory(
                this,"Save Location",QDir::homePath());

simply becomes

savDir.setPath(QFileDialog::getExistingDirectory(
                this,"Save Location",QDir::homePath()));
like image 28
Tim MB Avatar answered Nov 01 '25 16:11

Tim MB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!