当前位置: 代码迷 >> QT开发 >> Qt Android 继承QMessageBox诡异有关问题
  详细解决方案

Qt Android 继承QMessageBox诡异有关问题

热度:29   发布时间:2016-04-25 03:22:45.0
Qt Android 继承QMessageBox诡异问题

#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,可以正常运行了
求教啊
------解决方案--------------------
这种写法,还真很少见过。
一般来说QMessageBox不被继承,真的自己想写一个类似的对话框的话,请使用Qt的Designer来设计对话框。
  相关解决方案