最近用qt+html+js+qwechanel写了程序,在父窗口打开子窗口体,子窗口却糊到父窗口上?
(demobutton 这个按钮没有在childdemo的窗体中,被融合到父窗口中了)
怎么解决呢?
另外所以子窗口因为共享mainwindow中部分变量,所以必须接收window指针
如何解决?
增加重载方法,实例化用重载的方法实例化即可
js bridge 桥调用代码
//ChildDemo
QString JSQTBridge::getChildDemo()
{
QString reStr="Error";
Bustarget * targetBus=new Bustarget(this->window);
reStr=targetBus->getchildDemo();
reStr="OK";
return reStr;
}
demo列表
QString Bustarget::getchildDemo()
{
QString reStr="errof";
//childdemo *mydemoe=new childdemo(window);
//childdemo *mydemoe=new childdemo();
childdemo *mydemoe=new childdemo(nullptr,window);
mydemoe->show();
return reStr;
}
childdemo.h
#ifndef CHILDDEMO_H
#define CHILDDEMO_H
#include <QWidget>
namespace Ui {
class childdemo;
}
class childdemo : public QWidget
{
Q_OBJECT
public:
explicit childdemo(QWidget *parent = nullptr);
//扩展实现 [扩展重载] child 必须使用这个方式,否则会出现子窗口和mainwinodw糊在一起的现象
explicit childdemo(QWidget *parent = nullptr,QWidget *mainwinow = nullptr);
~childdemo();
private slots:
void on_pushButton_clicked();
private:
Ui::childdemo *ui;
private:
QWidget *window= nullptr;//父窗口 上下文
};
#endif // CHILDDEMO_H
childdemo.cpp
#include "childdemo.h"
#include "ui_childdemo.h"
#include "QMessageBox"
childdemo::childdemo(QWidget *parent) :
QWidget(parent),
ui(new Ui::childdemo)
{
this->window=parent;
ui->setupUi(this);
}
//扩展实现 [扩展重载]
childdemo::childdemo(QWidget *parent,QWidget *mainwinow ) :
QWidget(parent),
ui(new Ui::childdemo)
{
this->window=mainwinow;
ui->setupUi(this);
}
childdemo::~childdemo()
{
delete ui;
}
void childdemo::on_pushButton_clicked()
{
QMessageBox alert;
alert.warning(this,"提示","读取完成");
}
这个时候界面出来了