当我将项目从Qt5.12移到QT5.15时,这一行代码就中断了。
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);引发的错误如下:
mainwindow.cpp:28:5: error: cannot initialize object parameter of type 'QWidget' with an expression of type 'MainWindow'我正在进行这个迁移,因为QT建议在迁移到QT 6之前迁移到5.15,我也尝试过这样做,但也给出了同样的错误。
Qt::WindowFlags flags;
flags |= Qt::Window;
flags |=Qt::FramelessWindowHint;
setWindowFlags(flags);下面是整个MainWindow构造函数的代码--其中还有其他几个错误,但现在让我们关注这个错误。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
translator.load("://languages/translation_en.qm");
qApp->installTranslator(&translator);
//Initial UI setup.
#ifndef DESKTOP
/*
Qt::WindowFlags flags;
flags |= Qt::Window;
flags |=Qt::FramelessWindowHint;
setWindowFlags(flags);
*/
setWindowFlags(Qt::Window | Qt::FramelessWindowHint); //this is the line in question
setWindowState(Qt::WindowFullScreen);
#endif
ui->setupUi(this);
ui->remoteStatus->setVisible(false);
ui->simpleRemoteStatus->setVisible(false);
ui->simpleFrame->hide();
ui->dashboardFrame->hide();
ui->childFrame->hide();
startButtonDown = ui->simpleStartButton->isChecked();
stopButtonDown = ui->simpleStopButton->isChecked();
setupIcons();
//
double hmiver = 380;//version number
#ifdef CYCLE
hmiver = 999;
#endif
//Setup for Modbus Slave
thread = new QThread(this);
data = new DataThread();
data->moveToThread(thread);
connect(thread, SIGNAL(started()), data, SLOT(runProcess()));
//
setupMenus();
comsMod->RetainedData.HMIVer = hmiver;
comsMod->RTData.HMIVer = hmiver;
settingsMenu->aboutMenu->setHMIVer(hmiver);
setupTimers();
connectAll();
//Starts RTM communications on device side
DisplayCountTimer->setInterval(100);
DisplayCountTimer->start();
//After 2 seconds, starts remaining processes
StartModbusTimer->setInterval(2000);
StartModbusTimer->start();
/* Used for cycle testing */
#ifdef USBTEST
usbTest();
#endif
/* Used for cycle testing */
#ifdef CYCLE
this->on_productionButton_clicked();
#endif
}我正在研究Ubuntu 20.04
发布于 2022-09-20 23:09:48
我怀疑您切换到了QT5.15,但是您正在尝试将项目构建在与5.12相同的目录中。造成问题的原因是在旧编译之后仍然存在一些构建文件。在同一个目录中混合来自两个不同Qt版本的构建文件是100 %的灾难。
因此,它还报告了错误的行。我几乎可以肯定,有问题的行实际上是:ui->setupUi(this);而不是这个setWindowFlags(Qt::Window | Qt::FramelessWindowHint);。
我强烈建议有两个独立的构建目录。每个版本一个.
或者,如果您出于某种奇怪的原因只想要一个构建目录,那么始终删除上一个构建的内容。或者至少尝试重新运行qmake并尝试完全重建,但这有时可能不能很好地工作。它只是更肯定地删除所有的东西,从构建与先进的版本。
https://stackoverflow.com/questions/73790233
复制相似问题