Congratulations to our 2022 Qt Champions!

[SOLVED]c2568 unable to reolve overload == while trying to setup a print function

  • Trying to setup a really basic printing function, the code I've got so far is as follows.

           void PrintMenu::on_pushButton_2_clicked()
     QTextDocument* Document = ui->textBrowser->document();
    QPrinter Printer;
    QPrintDialog* printdialog = new QPrintDialog(&Printer, this);
    if (printdialog->exec()==&QPrintDialog::accepted)
    // Compiling fails here it says c2568 unable to resolve function overload == any suggestions as to how I could fix this? 

  • Moderators

    Should be:

    if (printdialog->exec() == QPrintDialog::Accepted) 

    notice the capital A and no &.
    Accepted is an enum value and accepted is a signal (a function), so your code tried to compare an int (the return value of exec()) and a function pointer, which there is no operator== for.

    Btw. It's usually easier to allocate dialogs like that on the stack. The above code leaks memory (printdialog instance).

  • @Chris-Kawa Thanks :)