为什么我不能使用智能指针来创建新的 QLineEdit 类

why i can't use the smart-pointer to make a new QLineEdit class

本文关键字:创建 QLineEdit 指针 不能 智能 为什么      更新时间:2023-10-16

如标题所示,我想通过智能销售QlineEdit类使用一些缓冲区,但是编译器显示" sizeof'的Invaild应用程序'sizeof'到不完整类型的'qlineedit'"。我通过BUIDIES消息找到了" Aligned_Buffer.h"文件。但这是无助的。我感到困惑的是,当我使用相同的方法将一些缓冲区用于qtextedit时,编译器成功了。为什么qlineedit不能使用同样的方式来做到这一点?

...
shared_ptr<QTextEdit> t1 = make_shared<QTextEdit>(); // successd
shared_ptr<QLineEdit> t2 = make_shared<QLineEdit>(); // failed
...

正确包含标头文件

#include <QTextEdit> // https://doc.qt.io/qt-5/qlineedit.html
#include <QLineEdit> // https://doc.qt.io/qt-5/qtextedit.html
#include <memory>     //https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared
int main(){
   shared_ptr<QTextEdit> t1 = std::make_shared<QTextEdit>(); 
   shared_ptr<QLineEdit> t2 = std::make_shared<QLineEdit>(); 
}