文章标题 原创 翻译 转载 文章内容 QLayout: Attempting to add QLayout , which already has a layout 出现这个警告的原因是一个QWidget作为了多个QLayout的parent,一个QWidget应该只有一个main layout,将其它子widget或者layout增加到main layout中,如下代码: ``` QWidget *x = new QWidget(this); QHBoxLayout *h1 = new QHBoxLayout(x); QHBoxLayout *h2 = new QHBoxLayout(x); ``` 会出现警告: > QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout ## 解决方法: ``` QWidget *x = new QWidget(this); QHBoxLayout *h1 = new QHBoxLayout(x); QHBoxLayout *h2 = new QHBoxLayout(); h1->addLayout(h2); ``` 或者给h2指定其它的widget作为parent。 文章类别 Python Mobile Android Java Shell Life Database Bug Windows IOS Tools Boost Node.js Mac Product Tips C/C++ Golang Javascript React Qt MQ MongoDB Design Web Linux LLM ChatGPT RAG AI 提交