【问题标题】:Qt: 'Q3DScatter' not recognized even though it is includedQt:即使包含“Q3DScatter”也无法识别
【发布时间】:2020-02-09 16:18:47
【问题描述】:

我想在我的主窗口中显示一个 3DScatter 图。

在我的 mainwindow.h 中,我包含了 #include <Q3DScatter>,但是当在 MainWindow 类的 public: 部分输入 3DScatter scatterGraph; 时,我收到以下错误消息:

error: unknown type name 'Q3DScatter'

这是我已经检查过的内容:

  • Qt 维护工具中已经安装了“Qt 数据可视化”模块
  • #include <Q3DScatter> 没有错误
  • 当转到 Tools -> Locate 并输入“Q3DScatter”时,它会同时找到 Q3DScatterq3dscatter.h
  • q3dscatter.h 中存在名为Q3DScatterPrivateQ3DScatter 的类
  • .pro 文件的第一行是QT += core gui datavisualization

我做错了什么?该模块似乎存在,但为什么我不能创建Q3DScatter scatterGraph

编辑: 这是来自编译输出的完整错误消息:

In file included from ../MandelbulbUI/main.cpp:1:0:
../MandelbulbUI/mainwindow.h:26:5: error: ‘Q3DScatter’ does not name a type; did you mean ‘QDate’?
     Q3DScatter scatterGraph;
     ^~~~~~~~~~
     QDate
In file included from ../MandelbulbUI/mainwindow.cpp:1:0:
../MandelbulbUI/mainwindow.h:26:5: error: ‘Q3DScatter’ does not name a type; did you mean ‘QDate’?
     Q3DScatter scatterGraph;
     ^~~~~~~~~~
     QDate
In file included from moc_mainwindow.cpp:9:0:
../MandelbulbUI/mainwindow.h:26:5: error: ‘Q3DScatter’ does not name a type; did you mean ‘QDate’?
     Q3DScatter scatterGraph;
     ^~~~~~~~~~
     QDate
Makefile:1598: recipe for target 'main.o' failed
make: *** [main.o] Error 1
make: *** Waiting for unfinished jobs....
Makefile:1817: recipe for target 'moc_mainwindow.o' failed
make: *** [moc_mainwindow.o] Error 1
Makefile:1805: recipe for target 'mainwindow.o' failed
make: *** [mainwindow.o] Error 1
17:30:54: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project MandelbulbUI (kit: Desktop Qt 5.12.7 GCC 64bit)
When executing step "Make"

【问题讨论】:

  • 你确定不只是你的 IDE 报错了吗?编译程序时,complete 编译器错误消息(如果有)是什么?
  • 我用编译器的错误信息更新了问题。
  • 你确定Q3DScatter 等没有在它们自己的命名空间下声明吗?
  • 我不确定。老实说,我什至不知道这意味着什么,以及为什么这里有必要。

标签: c++ qt


【解决方案1】:

快速查看标题表明Q3DScatter 在命名空间QtDataVisualization 下声明。既然如此,你就需要使用...

QtDataVisualization::Q3DScatter scatterGraph;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2021-06-26
    • 2023-03-09
    • 2020-03-06
    相关资源
    最近更新 更多