我在Qt(MSVC ++ 2008)中做了一些简单的程序,只有很少的复选框和按钮。在调试模式下,一切正常,但我不能分发这样的可执行文件,因为大多数人没有安装Visual Studio。当我在发布模式下编译它时,只有2个按钮工作。
我使用Qt Creator的'绘图工具'设计了我的窗口(Qt Designer,我猜)。 我的头文件中定义了这样的插槽:
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_clicked(); // Don't work, since theyre disabled
void on_outputBrowseButton_clicked(); // Same as above
void replyFinished(QNetworkReply *);
我对这些信号的实现如下:
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);
}
请原谅我的英语,并提前感谢你。
答案 0 :(得分:1)
您确定没有调用插槽 - 或者根本没有按照您的期望进行操作吗?
“它在调试中工作但不能发布”的最常见原因是单元化变量。在调试模式下,变量通常设置为某个零/零值,但不是在释放模式下。
另一个常见问题是带副作用的调试宏。你(或者一些lib)是否已经将connect()调用重写为用于调试的宏,并且它在发布时做了不同的事情?
一些printf()调试的时间?
答案 1 :(得分:1)
您的代码看起来不错。
尝试运行“make clean”或“qmake”。您的“ui_”或“moc_”文件可能需要更新。