0

This is the line of code that breaks when I moved my project from QT 5.12 to QT 5.15.

setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

The error that is thrown is the following:

mainwindow.cpp:28:5: error: cannot initialize object parameter of type 'QWidget' with an expression of type 'MainWindow'

I am doing this migration because QT recommends moving to 5.15 before moving to QT 6. I have tried doing it the following way as well but gives me the same error.

    Qt::WindowFlags flags;
    flags |= Qt::Window;
    flags |=Qt::FramelessWindowHint;
    setWindowFlags(flags);

Here is the code for the whole MainWindow constructor there are several more errors in it as well, but for now lets focus on this one.

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
}

I am working on Ubuntu 20.04

Brian
  • 1
  • 1
  • Which is line 28 of `mainwindow.cpp`? Also is there more text after this error message? I currently am having a difficulty matching the error to the code. – drescherjm Sep 20 '22 at 17:57
  • The first bit of code I posted is the line giving me the error and If you read the code I wrote in a comment next to the line that's giving me the error "this is the line in question" @drescherjm – Brian Sep 20 '22 at 18:16
  • this code works with the old version of qt 5.12 it just does not work when I upgraded to qt 5.15 – Brian Sep 20 '22 at 18:38
  • 1
    FWIW, I tried your code on 6.3.2 and didn't get any build issues. Are you sure you sourced the correct line as the error> – mzimmers Sep 20 '22 at 20:48
  • The error looks strange considering the line you are talking about. So if you comment out this line in question, your project builds correctly? Isn't the problematic line this `ui->setupUi(this);`? Please doublecheck... – HiFile.app - best file manager Sep 20 '22 at 23:03

1 Answers1

0

I suspect that you switched to Qt 5.15 but you are trying to build the project in the same directory as you did with 5.12. And the cause of your problems is that some build files remained there after the old compilation. Mixing build files from two different Qt versions in the same directory is a 100 % recipe for disaster.

Therefore it also reports wrong row. I am almost certain that the problematic row is actually this: ui->setupUi(this); instead of this setWindowFlags(Qt::Window | Qt::FramelessWindowHint);.

I strongly advice for having two separate build directories. One for each version.

Or, if you want just one build directory for some strange reason, then always delete the contents of the previous build. Or at least try re-running qmake and try complete rebuild, but this may sometimes not work well. It is just more certain to delete all stuff from the build with the prevous version.