Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:28+00:00 2026-05-23T00:01:28+00:00

in Qt im opening QDialog windows each time i click some item im doing

  • 0

in Qt im opening QDialog windows each time i click some item
im doing it with new , i like to be sure im opening only one instance of QDialog for each item
im clicking :

void foo::treeWidget_itemClicked(QTreeWidgetItem *item,nt column)                                               
    .....
    QString groupID = item->data(0, Qt::UserRole).toString();
    QString groupName = item->text(0);
    GroupDialogContainer* pGroupDialogContainer = new GroupDialogContainer(groupID,                                                                               groupName,                                                                                   this);

    pGroupDialogContainer->show();

}

class GroupDialogContainer : public QDialog
{
    Q_OBJECT


public:
    GroupDialogContainer(QString GroupId,QString GroupName,QWidget *parent=0); 
    GroupDialogContainer(QWidget *parent=0);
    virtual ~GroupDialogContainer();
    Ui::GroupDialog ui;

public slots:
    void closeEvent(QCloseEvent *event);
};

do i need to keep some kind of hash or vector of GroupDialogContainer ?
also my second question is :
does each time im closing the QDialog window with close () the object pGroupDialogContainer
that was responsible to open it is destroyer ed ? or do i need to delete it when im detecting that the QDIalog has closed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:01:29+00:00Added an answer on May 23, 2026 at 12:01 am

    Yes, you should probably keep some kind of list of your dialogs to keep track of which ones are already open. If your GroupID is your unique ID then you could do something like this:

    QMap DialogMap;

    void foo::treeWidget_itemClicked(QTreeWidgetItem *item,nt column)
    {
    …..
    QString groupID = item->data(0, Qt::UserRole).toString();

    if (! DialogMap.contains(groupID))
    {
      //  Popup the dialog and add it to map
      ...
      DialogMap.insert(groupID, pGroupDialogContainer);
    }
    

    }

    Now, for the other part. The most important thing is that you need to remove the item from the map when the dialog closes. You could either delete the dialog then, or my suggestion would be to let the dialog delete itself when it closes – as follows:

     // set automatic deletion of object on close
     setAttribute(Qt::WA_DeleteOnClose);
    

    But as I said, you’ll still need to remove the dialog from the Map, or else you’ll have a bad pointer in there, and your code will still think the dialog is open.

    So you’ll need some kind of signal from the dialog to indicate that it is closing. There is the finished(int result) signal, that is called when you trigger a result:

    This signal is emitted when the
    dialog’s result code has been set,
    either by the user or by calling
    done(), accept(), or reject().

    But, you can always create your own signal in your dialog, and emit it when the closeEvent is called in your dialog.

    Then in the code that handles the map…

    connect( pGroupDialogContainer, SIGNAL(WindowClosed()), this, SLOT(vCleanUpTheMap()));
    ...
    void vCleanUpTheMap()
    {
       GroupDialogContainer *pDialog = dynamic_cast<GroupDialogContainer *>(sender());
       if (pDialog)
       {
          // Just to keep things clean disconnect from the dialog.
          disconnect(pDialog);
    
          //  I am assuming that you can get the key groupID from the dialog
          //  Cause it's a lot easier to remove from a map with the key
          DialogMap.remove(pDialog->GetGroupID());
       }
    }
    

    And that’s it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
I'm opening up a new Outlook email from code in my windows application. Is
I'm opening a new browser window from my site for some of the members.
When opening a TIBQuery (IBQuery.Open), is the correspondig Transaction active only the time the
I'm opening new tab by click on button in the home page , and
Im opening a map like this: NSString *urlString = [NSString stringWithFormat:@http://maps.google.com/maps?q=%@,%@, destLat, destLong]; [[UIApplication
When opening new buffer it VIM, I type: new /path/to/fi If I hit tab
Javascript run at page opening or later by user action like clicking a button
I am opening a dialog box with a button click event. Dialog box contains
I notice that when opening .bash_history that it contains only the entries from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.