QtCreator 4.7
Qt5.11
でmainwindow
プロジェクトを立ち上げました。
pro
ファイルと、h
ファイル、そしてcpp
ファイルの3つが自動で出来上がるのですけれども、意味不明なエラーが出ます。
mainwindow.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
出現エラー
cannot initialize object parameter of type 'QWidget' with an
expression type 'MainWindow'
プロジェクトを立ち上げていただいて、全く改編をしていない初期状態のコードです。
qt creator 4.7をインストールされてらっしゃる方はすぐに作れる状態です。一応タイトルが似た質問を見付けましたがCannot initialize return object of type 'int' with an lvalue of type 'cocos2d::Scene *'は、cocoa2d-xのもので、qtではありませんでした。
一応他のコードも載せます。
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
};
#endif // MAINWINDOW_H
mainwindow.pro
#-------------------------------------------------
#
# Project created by QtCreator 2018-09-14T16:52:20
#
#-------------------------------------------------
QT += core gui widgets
TARGET = MainWindow
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
追記:
問題が起きない方の環境だと、こうなります。
qt 5.9.6
qt-creator 4.7.0
他は同じ。
ただし、コンパイラが、msvc2017であるのに対して、問題が起きるほうは、
min-GW32が選ばれ、これは、32bit
と書いてあります。おそらく、コンパイラ
のセットが不十分であるために起るバグだろうと考えていますが、推測の域を出ません。
インストール時に特に変わった設定はしていないつもりなのですが、なぜかこうなりました。
実行環境
Windows 10
64bit
qt-creator 4.7
c++11
qt 5.11
mainwindow.pro
の内容が誤っているように見受けます。訂正されたほうがよいと思います。QtCreator
4.7だと、コンパイル前にコード解析が動作すると思いますが、質問のエラーはコード解析で出ますか? あるいはコンパイル時に出ますか?