Results 1 to 8 of 8

Thread: Multiple QWidgets

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Multiple QWidgets

    Hello friends, now I try to locate my error in my logic.

    here are a piece of my app:

    Qt Code:
    1. //**************************************************************************
    2. void MdlProjektErstellung::newOrderSpace()
    3. //**************************************************************************
    4. {
    5. bool ok1,ok2;
    6. QString dir = QFileDialog::getExistingDirectory(this, tr("open group path"),
    7. "C:",
    8. QFileDialog::ShowDirsOnly
    9. | QFileDialog::DontResolveSymlinks);
    10. QString WorkspaceName = QInputDialog::getText(this, tr("groupname"),
    11. tr("Group"), QLineEdit::Normal,
    12. "Name", &ok1);
    13. QString ProjektAnzahl = QInputDialog::getText(this, tr("Projektinput"),
    14. tr("Projektcount"), QLineEdit::Normal,
    15. "1", &ok2);
    16.  
    17. vector<string> vecProjektDateien;
    18. this->m_actualWorkSpaceFile.clear();
    19. this->m_actualWorkSpaceFile.append(dir);
    20. this->m_actualWorkSpaceFile.append("/");
    21. this->m_actualWorkSpaceFile.append(WorkspaceName);
    22. this->m_actualWorkSpaceFile.append(".ert");
    23. OrderSpace* ActualSpace = new OrderSpace(dir.toAscii().data(),
    24. WorkspaceName.toAscii().data(),
    25. ProjektAnzahl.toInt(),
    26. vecProjektDateien);
    27. tableModel = new QStandardItemModel;
    28. tableModel->setRowCount(0) ;
    29. int Max_Number_of_Columns(1);
    30. int Max_Number_of_Lines(0);
    31. tableModel->setColumnCount(Max_Number_of_Columns) ;
    32.  
    33. for (vector <string>::iterator vItr=vecProjektDateien.begin(); vItr != vecProjektDateien.end(); ++vItr)
    34. {
    35. string tstr=(*vItr).c_str();
    36. QStandardItem * item = new QStandardItem(tstr.c_str());
    37. tableModel->setItem(Max_Number_of_Lines, 0, item) ;
    38.  
    39. Max_Number_of_Lines++;
    40. }
    41.  
    42. this->myOrderView->setModel(tableModel);
    43. this->myOrderView->setAlternatingRowColors(true);
    44. this->myOrderView->resizeColumnsToContents();
    45. this->myOrderView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    46.  
    47. connect(this->myOrderView, SIGNAL(clicked(const QModelIndex)), this, SLOT(GetProjectItem(const QModelIndex &)));
    48.  
    49.  
    50. }
    51.  
    52.  
    53. //**************************************************************************
    54. void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
    55. //**************************************************************************
    56. {
    57. QString str;
    58. str=tableModel->data(index,0).toString();
    59.  
    60. MdlProjektMaske* AktProjektMaske = new MdlProjektMaske(str,this->m_actualWorkSpaceFile);
    61. AktProjektMaske->show();
    62. //connect(AktProjektMaske, SIGNAL(closed()), AktProjektMaske, SLOT(deleteLater()));
    63. }
    To copy to clipboard, switch view to plain text mode 

    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.....

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Multiple QWidgets

    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?

  3. The following user says thank you to Lykurg for this useful post:

    codeman (23rd March 2010)

  4. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Multiple QWidgets

    In the Contructor of MdlProjektMaske I still use
    Qt Code:
    1. this->setAttribute(Qt::WA_DeleteOnClose);
    To copy to clipboard, switch view to plain text mode 

    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..

  5. #4
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Multiple QWidgets

    Ok now I implement a Dialog class as member and use it in my func like this

    Qt Code:
    1. //**************************************************************************
    2. void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
    3. //**************************************************************************
    4. {
    5.  
    6.  
    7. this->setAttribute(Qt::WA_DeleteOnClose,true);
    8. this->mymask->exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

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

  6. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple QWidgets

    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

  7. The following user says thank you to JohannesMunk for this useful post:

    codeman (23rd March 2010)

  8. #6
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Multiple QWidgets

    And this one also gets multiple Dialogs

    Qt Code:
    1. //**************************************************************************
    2. void MdlProjektErstellung::GetProjectItem(const QModelIndex& index)
    3. //**************************************************************************
    4. {
    5. QString str;
    6. str=tableModel->data(index,0).toString();
    7.  
    8. this->mymask = new dlgPrjMaske;
    9. this->mymask->setAttribute(Qt::WA_DeleteOnClose,true);
    10. this->mymask->exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

  9. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Multiple QWidgets

    @ Johannes Munk Thank You very very very much I take the next best wall Ohhh mannnn How could I overlook...

    really thank youu

  10. #8
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiple QWidgets

    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

Similar Threads

  1. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 17:01
  2. Navigate between QWidgets and MainWindow
    By pcaeiro in forum Qt Programming
    Replies: 2
    Last Post: 5th August 2009, 12:05
  3. QWidgets and QPixmaps and Stylesheets .... oh my.
    By steb in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2009, 07:50
  4. finding QWidgets in QList
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 26th July 2008, 11:58
  5. QTableView, add QWidgets
    By xgoan in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2006, 18:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.