Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Lifetime Qt Champion

    @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



  • @jsulm i sort of know, can u correct the code for me?? i saw the document, bt can't get a hold of it....


  • Lifetime Qt Champion

    @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...


Log in to reply