我想分配父變量(在子類的構造函數),然後我想使它成爲子類的成員變量。我怎麼能在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(QWidget的*父) {// 我需要父存儲在變量贏,並使其PopupServer 類的成員變量} 無效PopupServer :: showPopup(常量QString的&文本,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(); } – Vector
你想在課堂的任何地方訪問父母嗎? – eyllanesc