PDA

View Full Version : Multiple QWidgets



codeman
22nd March 2010, 20:08
Hello friends, now I try to locate my error in my logic.

here are a piece of my app:



//************************************************** ************************
void MdlProjektErstellung::newOrderSpace()
//************************************************** ************************
{
bool ok1,ok2;
QString dir = QFileDialog::getExistingDirectory(this, tr("open group path"),
"C:",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
QString WorkspaceName = QInputDialog::getText(this, tr("groupname"),
tr("Group"), QLineEdit::Normal,
"Name", &ok1);
QString ProjektAnzahl = QInputDialog::getText(this, tr("Projektinput"),
tr("Projektcount"), QLineEdit::Normal,
"1", &ok2);

vector<string> vecProjektDateien;
this->m_actualWorkSpaceFile.clear();
this->m_actualWorkSpaceFile.append(dir);
this->m_actualWorkSpaceFile.append("/");
this->m_actualWorkSpaceFile.append(WorkspaceName);
this->m_actualWorkSpaceFile.append(".ert");
OrderSpace* ActualSpace = new OrderSpace(dir.toAscii().data(),
WorkspaceName.toAscii().data(),
ProjektAnzahl.toInt(),
vecProjektDateien);
tableModel = new QStandardItemModel;
tableModel->setRowCount(0) ;
int Max_Number_of_Columns(1);
int Max_Number_of_Lines(0);
tableModel->setColumnCount(Max_Number_of_Columns) ;

for (vector <string>::iterator vItr=vecProjektDateien.begin(); vItr != vecProjektDateien.end(); ++vItr)
{
string tstr=(*vItr).c_str();
QStandardItem * item = new QStandardItem(tstr.c_str());
tableModel->setItem(Max_Number_of_Lines, 0, item) ;

Max_Number_of_Lines++;
}

this->myOrderView->setModel(tableModel);
this->myOrderView->setAlternatingRowColors(true);
this->myOrderView->resizeColumnsToContents();
this->myOrderView->setEditTriggers(QAbstractItemView::NoEditTriggers) ;

connect(this->myOrderView, SIGNAL(clicked(const QModelIndex)), this, SLOT(GetProjectItem(const QModelIndex &)));


}


//************************************************** ************************
void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
//************************************************** ************************
{
QString str;
str=tableModel->data(index,0).toString();

MdlProjektMaske* AktProjektMaske = new MdlProjektMaske(str,this->m_actualWorkSpaceFile);
AktProjektMaske->show();
//connect(AktProjektMaske, SIGNAL(closed()), AktProjektMaske, SLOT(deleteLater()));
}


when I run newOrderSpace() my tableview fills with Item and when I click on them getProjectItem() runs. And I get my Qwidget AktProjektMaske.

The Problem now when I run newOrderSpace n times I get n QWidgets when I click on my Item on Tableview.
Whats wrong here friends??

P.S.: MdlProjektErstellung is a Widget in my QStackedWidget from Mainwindow.....

Lykurg
22nd March 2010, 20:14
Use a member variable for MdlProjektMaske and reuse it or use the widget attribute Qt::WA_DeleteOnClose. But why are you using a widget and no dialog? where is MdlProjektMaske shown?

codeman
23rd March 2010, 09:35
In the Contructor of MdlProjektMaske I still use
this->setAttribute(Qt::WA_DeleteOnClose);

but nothing changes. I also try to replace QWidget with QDilaog same result multiple widgets there seemss to be a knowledge gap by me..

but where to go..

codeman
23rd March 2010, 11:30
Ok now I implement a Dialog class as member and use it in my func like this



//************************************************** ************************
void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
//************************************************** ************************
{


this->setAttribute(Qt::WA_DeleteOnClose,true);
this->mymask->exec();
}


same thing I get n Dialogs after I clode the one it pop up a new dialog

JohannesMunk
23rd March 2010, 12:07
The problem is that the connect-statement is executed n times. Then every time the signal is emitted the slot is called n times..Thats why you get n dialogs. You need to set this up in a constructor!

HIH

Johannes

codeman
23rd March 2010, 12:10
And this one also gets multiple Dialogs



//************************************************** ************************
void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
//************************************************** ************************
{
QString str;
str=tableModel->data(index,0).toString();

this->mymask = new dlgPrjMaske;
this->mymask->setAttribute(Qt::WA_DeleteOnClose,true);
this->mymask->exec();
}

codeman
23rd March 2010, 12:16
@ Johannes Munk Thank You very very very much I take the next best wall Ohhh mannnn How could I overlook...

really thank youu

JohannesMunk
23rd March 2010, 12:21
Glad to be of assistance!

And: Skip the wall! This exact same thing, happened to me once, too.. We only learn from our mistakes..

Joh