2

I'm using QT 6.4.2 at Windows that write App, but when I need to use QHBoxLayout, I get

error:Unknown type name 'QHBoxLayout'

so I open help document in QT, that found sample about QHBoxLayout, I according to official document create a new project that is very simple:

.pro file is

QT       += core gui widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp

HEADERS +=

FORMS +=

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp is

#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *window = new QWidget;
    QPushButton *button1 = new QPushButton("One");
    QPushButton *button2 = new QPushButton("Two");
    QPushButton *button3 = new QPushButton("Three");
    QPushButton *button4 = new QPushButton("Four");
    QPushButton *button5 = new QPushButton("Five");
    QHBoxLayout *layout = new QHBoxLayout(window);
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);
    window->show();
    return a.exec();
}

Below is some picture at Windows:

enter image description here

enter image description here

pro file

Below is Windows QT version and kit setting:

enter image description here

enter image description here

enter image description here

I try to clean and re-build many times, but it still can't work. I also can't find out what reason cause the problem, so I try to open the same project with QT(6.4.1 version) at MacBook Pro, The same project can surprisingly be compiled successfully and generate executable programs on the Mac platform.

Below is some picture at MacBook Pro:

enter image description here

enter image description here

So is that QT latest version's Bug at Windows? How can I solve this problem?

First update

As @HiFile.app - best file manager said, when I change QHBoxLayout to QVBoxLayout, it seems still can't work when compile, see below picture.

enter image description here

Now my main.cpp file is :

#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *window = new QWidget;
    QPushButton *button1 = new QPushButton("One");
    QPushButton *button2 = new QPushButton("Two");
    QPushButton *button3 = new QPushButton("Three");
    QPushButton *button4 = new QPushButton("Four");
    QPushButton *button5 = new QPushButton("Five");
    QVBoxLayout *layout = new QVBoxLayout(window);
    layout->addWidget(button1);
    layout->addWidget(button2);
    layout->addWidget(button3);
    layout->addWidget(button4);
    layout->addWidget(button5);
    window->show();
    return a.exec();
}

I installed QT through the following method:

enter image description here

Currently, I have only found issues with QHBoxLayout and QVBoxLayout, and have not discovered any issues with other controls for the time being.

Where did the problem occur?

Second update

When I use below command:

qmake.exe ChangeFontSize.pro

will generate Makefile file.

then I use "Developer Command Prompt for VS 2022" to run below command:

nmake release

for compile also get same error

C:\my-win10-document\code\ChangeFontSize>nmake release

Microsoft (R) 程序维护实用工具 14.33.31630.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        C:\my-win10-document\software---install\VS--install\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\nmake.exe -f Makefile.Release

Microsoft (R) 程序维护实用工具 14.33.31630.0 版
版权所有 (C) Microsoft Corporation。  保留所有权利。

        C:\my-win10-document\software---install\QT--install\6.4.2\mingw_64\bin\uic.exe mainwindow.ui -o ui_mainwindow.h
        g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -I../../software---install/QT--install/6.4.2/mingw_64/include -I../../software---install/QT--install/6.4.2/mingw_64/include/QtWidgets -I../../software---install/QT--install/6.4.2/mingw_64/include/QtGui -I../../software---install/QT--install/6.4.2/mingw_64/include/QtCore -Irelease -I. -I/include -I../../software---install/QT--install/6.4.2/mingw_64/mkspecs/win32-g++ -o release\main.o main.cpp
        g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I. -I../../software---install/QT--install/6.4.2/mingw_64/include -I../../software---install/QT--install/6.4.2/mingw_64/include/QtWidgets -I../../software---install/QT--install/6.4.2/mingw_64/include/QtGui -I../../software---install/QT--install/6.4.2/mingw_64/include/QtCore -Irelease -I. -I/include -I../../software---install/QT--install/6.4.2/mingw_64/mkspecs/win32-g++ -o release\mainwindow.o mainwindow.cpp
mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:29:6: error: 'QHBoxLayout' was not declared in this scope; did you mean 'QLayout'?
   29 |      QHBoxLayout *hLayout = new QHBoxLayout;
      |      ^~~~~~~~~~~
      |      QLayout
mainwindow.cpp:29:19: error: 'hLayout' was not declared in this scope; did you mean 'QLayout'?
   29 |      QHBoxLayout *hLayout = new QHBoxLayout;
      |                   ^~~~~~~
      |                   QLayout
mainwindow.cpp:29:33: error: 'QHBoxLayout' does not name a type; did you mean 'QLayout'?
   29 |      QHBoxLayout *hLayout = new QHBoxLayout;
      |                                 ^~~~~~~~~~~
      |                                 QLayout
mainwindow.cpp:34:6: error: 'QVBoxLayout' was not declared in this scope; did you mean 'QLayout'?
   34 |      QVBoxLayout *vLayout = new QVBoxLayout;
      |      ^~~~~~~~~~~
      |      QLayout
mainwindow.cpp:34:19: error: 'vLayout' was not declared in this scope; did you mean 'QLayout'?
   34 |      QVBoxLayout *vLayout = new QVBoxLayout;
      |                   ^~~~~~~
      |                   QLayout
mainwindow.cpp:34:33: error: 'QVBoxLayout' does not name a type; did you mean 'QLayout'?
   34 |      QVBoxLayout *vLayout = new QVBoxLayout;
      |                                 ^~~~~~~~~~~
      |                                 QLayout
NMAKE : fatal error U1077: “C:\my-win10-document\software---install\QT--install\Tools\mingw1120_64\bin\g++.EXE”: 返回代码“0x1”
Stop.
NMAKE : fatal error U1077: “C:\my-win10-document\software---install\VS--install\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\nmake.exe”: 返回代码“0x2”
Stop.

Here is picture:

enter image description here

Third update

I created a new project again for test QWidget and QPushButton in Windows platform that can work. See below picture.

enter image description here

But when I only new add two line code in main.cpp (No changes have been made elsewhere), then compile will get error, see below picture:

enter image description here

So far, I have confirmed that using QHBoxLayout and QVBoxLayout is problematic.

Tom
  • 417
  • 3
  • 10
  • This is a very strange bug, I have never encountered such a problem - and I am using Qt 6.4.2 too for a widget application without any issues. So maybe a stupid suggestion: did you try to re-run qmake for your project? Btw. the About box for your QtCreator does show the version with which your QtCreator was built and does not show your actual Qt framework version. Are you sure you are using 6.4.2? Check Projects settings to see the version and check Preferences->Kits if your paths are correct. – HiFile.app - best file manager Mar 13 '23 at 08:07
  • @HiFile.app-bestfilemanager I have try to clean and re-rebuild many times,but still doesn't work. I'm sure I use QT 6.4.2 at windows(See above picture). I will update my question that show Preferences->Kits if my paths are correct. – Tom Mar 13 '23 at 08:19
  • @HiFile.app-bestfilemanager Can you find out where is problem? Please help me solve this problem. – Tom Mar 13 '23 at 08:40
  • I am afraid, I have no idea what may be wrong. You can try other Qt version (e.g. the latest LTS version 6.2.4) or MSVC version (but it will require to install MS build tools). I have never used MinGW tools on Windows, so I have no experience with them... – HiFile.app - best file manager Mar 13 '23 at 10:03
  • Is the problem only with `QHBoxLayout`? What happens if you change `QHBox...` to `QVBox...`? Will that work? (I am not suggesting that you redefine your layouts, I am just trying to diagnose the problem) – HiFile.app - best file manager Mar 13 '23 at 10:08
  • @HiFile.app-bestfilemanager ,I update my question as you said change QHBoxLayout to QVBoxLayout, it seems still can't work when compile. – Tom Mar 13 '23 at 10:18
  • @HiFile.app-bestfilemanager Currently, I have only found issues with QHBoxLayout and QVBoxLayout, and have not discovered any issues with other controls for the time being. I create that project(officical sample) just check QVBoxLayout and QHBoxLayout if work ok. – Tom Mar 13 '23 at 11:09
  • If you create a new project (the sample which you show without VBoxLayout) and then compare the generated .pro file with the .pro file shich you have for your project with QVBoxLayout... are there any differences? What is you try to include and use `QVBoxLyaout` in the new project? Will it work? What happens if you move include to the very top above ? Still the same problem? (sorry, these might sound stupid, but these are just diagnostics checks which might help) – HiFile.app - best file manager Mar 13 '23 at 14:20
  • @HiFile.app-bestfilemanager According to the method you mentioned, so far, I have confirmed that using QHBoxLayout and QVBoxLayout is problematic. See my question update about "Third update". I test heard file #include placed in the first line or the second line or the third line,it don't matter(or it is not important), still get error when compile. – Tom Mar 13 '23 at 23:05
  • @HiFile.app-bestfilemanager I solved the problem by reinstalling QT by myself, and now it can be used normally. Thank you very much! – Tom Mar 14 '23 at 11:07

1 Answers1

0

I solved the problem by reinstalling QT by myself, and now it can be used normally.

enter image description here

Tom
  • 417
  • 3
  • 10