copyavailable(), undoavailable()
-
can anyone explain copyavailable() and undoredoavaiable() functions with some code?? and what's wrong with this code??
void MainWindow::on_actioncopy_triggered()
{
if(ui->textEdit->copyAvailable((bool))){
ui->textEdit->copy();
else{
QMessageBox::information(this,"FYI","Select something first");}}
void MainWindow::on_actionpaste_triggered()
{
if(ui->textEdit->canPaste())
ui->textEdit->paste();
else
QMessageBox::information(this,"FYI","Copy something first");
}void MainWindow::on_actioncut_triggered()
{
if(ui->textEdit->copyAvailable(isEnabled()))
ui->textEdit->cut();
else
QMessageBox::
information(this,"FYI","Select something first");
}void MainWindow::on_actionundo_triggered()
{
if(ui->textEdit->undoAvailable() == true)
ui->textEdit->setUndoRedoEnabled(isEnabled());
else
QMessageBox::
information(this,"FYI","nothing to undo");
}
if any edit needed, plz feel free to suggest -
@tanim2607 This code does not make sense.
copyAvailable is a SIGNAL and does not return a boolean, also "if(ui->textEdit->copyAvailable((bool))){" is not valid C++ code. You need to connect a slot to copyAvailable. Read https://doc.qt.io/qt-5/signalsandslots.html
Please read https://doc.qt.io/qt-5/qtextedit.html#copyAvailable -
@tanim2607 said in copyavailable(), undoavailable():
can u correct the code for me??
It's your job.
As I wrote: connect a slot to copyAvailable signal.
If you have problems/don't understand something then ask concrete questions. But don't ask others to write code for you - you will hardly learn anything this way...
4/4