friend class - or what else to do?
I have a QTabWidget with four tabs. The only one enabled to start with is the first, called Welcometab.
All tabs are QWidgets, with different content.
The Welcome widget holds som QLabels, with Project-info.
When you press Ctrl+N, you get a dialog where you can fill in Project data. If data are accepted, the are transferred to a QDomDocument and saved. This works fine.
My problem is to transfer the Project data to the labels on the front Tab. How do I do that?
Right now I am trying with friend classes.
Lani is the clas called from main().
I include "welcometab.h" and have and empty declaration of the Welcometab class. In the Welcometab class I declare Lani as a friend. Is this not right?
From Lani.h:
Code:
#include "welcometab.h"
class WelcomeTab;
{
Q_OBJECT
from welcometab.h:
Code:
{
Q_OBJECT
public:
explicit WelcomeTab
(QWidget *parent
= 0);
friend class Lani;
I hope you can help. Thank You!
David
Re: friend class - or what else to do?
This is not a Qt question as far as I understand.
1. use QFile to store the project data(as xml file)
2. or hold your project data as a member of your tab's parent widget.
Re: friend class - or what else to do?
I have used QFile, and store the project data as xml. It works fine.
Besides that I want to write Project details om the Welcome-tab
Here is the "welcometab.cpp" file:
Code:
#include "welcometab.h"
WelcomeTab
::WelcomeTab(QWidget *parent
) :{
view = new QWebView(parent);
view->setMinimumWidth(700);
leftbox->addWidget(view);
labProjName
= new QLabel(tr
("Project Name:"),
this);
infoLayout->addWidget(labProjName);
labProjNameText
= new QLabel("",
this);
infoLayout->addWidget(labProjNameText);
rightbox->addLayout(infoLayout);
rightbox->addStretch();
layout->setSpacing(0);
layout->addLayout(leftbox);
layout->addLayout(rightbox);
setLayout(layout);
}
void WelcomeTab
::setTextProjName(QString s
){ labProjNameText->setText(s);
}
In the Lani.cpp constructor you'll find:
Code:
tabWidget->setShortcutEnabled(0,true);
welcomeTab = new WelcomeTab();
tabWidget->addTab(welcomeTab,tr("&1 Welcome"));
In Lani.h I declare welcomeTab:
What I can't understand is: Why can't I write
Code:
welcomeTab.setTextProjName("somestring");
It really puzzles me...
Re: friend class - or what else to do?
Ok but, where you think you read the project name? From the file you created right?
If so, then you need to open that file and gather it's contents very much like;
Code:
doc.setContent( yourProjectXMLFile->readAll(),..);
then
Code:
QString proj_name
= doc.
attribute(tagname
);
then
Code:
welcomeTab->setProfName(prof_name);
Re: friend class - or what else to do?
Thanks for the suggestions, and your help.
I've just discovered the mistake that has been haunting me the last three days.
I declared welcomeTab as a QWidget?!
It is not a QWidget - it is a WelcomeTab...
Thanks again, and excuse my sillyness (Arghhhhhhhhhh!)