私は、(子クラスのコンストラクタで)変数に親を割り当てようとしていますが、子クラスのメンバ変数にしたいと思います。 Qtでどうすればいいですか?Qt:その子クラスのメンバ変数として親を設定する方法は?
コード:
PopupServer::PopupServer(QWidget *parent) {
//I need to store the parent in variable Win
//and make it member variable of PopupServer class
}
void PopupServer::showPopup(const QString &text,const int &tim) {
QLabel qPopup= new QLabel; qPopup.setText(text);
qPopup.setFrameStyle(QLabel::Raised | QLabel::Panel);
qPopup.setAlignment(Qt::AlignCenter);
qPopup.setFixedSize(200,100);
int width;
int height;
width= win.width();
height= win.height();
qPopup.move(width-qPopup.width(),height-qPopup.height());
qPopup.show();
}
あなたのコードを表示してください。 – eyllanesc
PopupServer :: 無効PopupServer {私は変数勝利に親を保存し、それをPopupServerクラス のメンバ変数を作成する必要があり //} PopupServer(QWidgetの*親) :: showPopup(のconst QStringの&テキスト、のconst int型&ティム) { QLabel qPopup =新しいQLabel; qPopup.setText(text); qPopup.setFrameStyle(QLabel :: Raised | QLabel :: Panel); qPopup.setAlignment(Qt :: AlignCenter); qPopup.setFixedSize(200,100); int幅; int高さ; width = win.width(); height = win.height(); qPopup.move(width-qPopup.width()、height-qPopup.height()); qPopup.show(); } – Vector
クラスのどこにでも親にアクセスしますか? – eyllanesc