J
J
jackroll2014-09-21 12:27:31
C++ / C#
jackroll, 2014-09-21 12:27:31

Can't use branch operations in Qt?

// ... code!

void MyDialog::EnableOk()
{
    ui->okbutton->setEnabled(ui->lineEdit->hasAcceptableInput());
    switch(ui->okbutton->clicked())
    {
        default:
        QMessageBox *msg = new QMessageBox;
        msg->setText("TEST!!!");
        msg->exec();
        break;
    }
}

// ... code!

When I try to compile I get an error:
C2450: switch expression of type 'void' is illegal
Expressions of type void cannot be converted to other types
I tried to write like this:
void MyDialog::EnableOk()
{
    ui->okbutton->setEnabled(ui->lineEdit->hasAcceptableInput());
    bool b = ui->okbutton->clicked();
    switch(b)
    {
    default:
        QMessageBox *msg = new QMessageBox;
        msg->setText("TEST!!!");
        msg->exec();
        break;
    }
}

Error:
C2440: 'initializing' : cannot convert from 'void' to 'bool'
Expressions of type void cannot be converted to other types
What should I do? How to fix? Why is this happening?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlexP11223, 2014-09-21
@jackroll

What do you want to achieve with such a strange design? What makes you think that clicked() should return bool? The compiler also says that it is void (and in general it is a signal, you can only emit it or connect a slot to it).

S
Sergey, 2014-09-21
Protko @Fesor

ui->okbutton->clicked() seems to return void. Further to read texts of errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question