Qt Android 继承QMessageBox诡异问题

看山不是山看水不是水 2014-03-13 09:49:06

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMessageBox>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMessageBox
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H


#include<QPushButton>
#include<QVBoxLayout>
#include<QLabel>

MainWindow::MainWindow(QWidget *parent) :
QMessageBox(parent)
// ui(new Ui::MainWindow)
{
// ui->setupUi(this);
QPushButton* m_pBtnOk = new QPushButton( tr( "是" ) );
QPushButton* m_pBtnCancel = new QPushButton( tr( "否" ) );
QHBoxLayout* pHLayout = new QHBoxLayout();
pHLayout->addWidget( m_pBtnOk );
pHLayout->addWidget( m_pBtnCancel );

QLabel*m_pLblText = new QLabel;

QLayout* pLayout = layout();
if( pLayout )
delete pLayout;
QVBoxLayout* pMainLayout = new QVBoxLayout( this );
pMainLayout->addWidget( m_pLblText,0, Qt::AlignHCenter );
pMainLayout->addLayout( pHLayout );

setLayout( pMainLayout );

}

MainWindow::~MainWindow()
{
// delete ui;
}

上面的代码 输出调试提示这个:
W/ResourceType(10229): Attempt to retrieve bag 0x010302ff which is invalid or in a cycle.
W/ResourceType(10229): Attempt to retrieve bag 0x010302e4 which is invalid or in a cycle.
然后界面就是白白的一片在上面有一道黑线
但是MainWindow改成继承自QDialog,可以正常运行了
求教啊
...全文
167 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
彩阳 2014-04-27
  • 打赏
  • 举报
回复
这种写法,还真很少见过。 一般来说QMessageBox不被继承,真的自己想写一个类似的对话框的话,请使用Qt的Designer来设计对话框。

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧