开发者

Qt: some slots don't get executed in release mode

开发者 https://www.devze.com 2023-04-11 05:53 出处:网络
I am doing some simple program in Qt (MSVC++2008) with few checkboxes and buttons. In debug mode, everything works fine, but I can\'t distribute such executable, because most people don\'t have Visual

I am doing some simple program in Qt (MSVC++2008) with few checkboxes and buttons. In debug mode, everything works fine, but I can't distribute such executable, because most people don't have Visual Studio installed. When I do compile it in release mode, only 2 pushbuttons work.

I have designed my window using Qt Creator's 'drawing tool' (Qt Designer, I guess). I do have such slots defined in my header file:

private slots:
    void on_goButton_clicked(); // Works fine

    void on_InputCheckBox_stateChanged(int arg1); // Don't work
    void on_outputFileCheckBox_stateChanged(int arg1); // Same as above

    void on_inputBrowseButton_clicke开发者_运维技巧d();  // Don't work, since theyre disabled
    void on_outputBrowseButton_clicked(); // Same as above

    void replyFinished(QNetworkReply *);

My implentation of those signals looks like this:

void MainWindow::on_InputCheckBox_stateChanged(int arg1)
{
    if (arg1 == Qt::Checked)
    {
        ui->inputEdit->setEnabled(true);
        ui->inputBrowseButton->setEnabled(true);
     }
    else
    {
        ui->inputEdit->setEnabled(false);
        ui->inputBrowseButton->setEnabled(false);
    }
}

void MainWindow::on_outputFileCheckBox_stateChanged(int arg1)
{
    if (arg1 == Qt::Checked)
    {
        ui->outputEdit->setEnabled(true);
        ui->outputBrowseButton->setEnabled(true);
    }
    else
    {
        ui->outputEdit->setEnabled(false);
        ui->outputBrowseButton->setEnabled(false);
    }
}

void MainWindow::on_inputBrowseButton_clicked()
{
    QString documents = DesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    QString filename = QFileDialog::getOpenFileName(
            this,
            tr("Select input file"),
            documents,
            tr("Text files (*.txt);;All files (*)"));
    if (filename.size() == 0)
        return;
    else
         ui->inputEdit->setText(filename);
}

void MainWindow::on_outputBrowseButton_clicked()
{
    QString documents = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    QString filename = QFileDialog::getOpenFileName(
            this,
            tr("Select output file"),
            documents,
            tr("Text files (*.txt);;All files (*)"));
    if (filename.size() == 0)
        return;
    else
        ui->inputEdit->setText(filename);
}

Pardon for my English and thank you in advance.


Your code looks good.

Try running "make clean" or "qmake". Your "ui_" or "moc_" files might need updating.


Are you sure the slots aren't being called - or simply not doing what you expect?

The most common reason for 'it works in debug but not release' is unitialised variables. In debug mode the variables are generally set to some null/zero value but not in release mode.

Another common problem are debug macros with side effects. Have you (or some lib) rewritten the connect() call as a macro for debugging and it's doing something different in release?

Time for some printf() debugging ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号