PDA

View Full Version : load a Window



sabeesh
20th August 2007, 13:19
Hi,
I have a program in QT. In that program I create a tree using QTreeView. When I double click on an item in the tree, at that time I need to create a Window. I do that, and it is working. My probs is that, When I double click on an item, then it create a new window and again i double click on the same item, I need to show the old window. But in my program, it create a new window. For each time the name of the window is change ( the text of the item) How can I check the name ( the window withe a name ) is loaded?
Please help me..........

Michiel
20th August 2007, 13:32
Hi,
I have a program in QT. In that program I create a tree using QTreeView. When I double click on an item in the tree, at that time I need to create a Window. I do that, and it is working. My probs is that, When I double click on an item, then it create a new window and again i double click on the same item, I need to show the old window.

Well, this doesn't have much to do with Qt. You just have to map tree-items to window-pointers in your program (initiate all the pointers to NULL). When someone double-clicks on an item, you check if the associated window-pointer is NULL (meaning: a window has not yet been created). If so, create the window. Then show the window either way.

At least, that's how I'd do it.


But in my program, it create a new window. For each time the name of the window is change ( the text of the item) How can I check the name ( the window withe a name ) is loaded?

I don't really understand what you mean here. Try my suggestion. If it doesn't help, please explain more clearly what you want your program to do.

sabeesh
20th August 2007, 13:44
Hi,
I have tree in my program. The nodes in the trees are 'Camera 1', 'Camera 2', 'Camera 3', etc. When I double click on the node 'Camera 1' then a window is created named as 'Camera_1', when I double click on nod 'Camera 2' then a nother window is load named as 'Camera_2' like that.....
My problem is that, When I double click on a node, 'Camera 1' at first time, then a new window is created and load name of that window is 'Camera_1' and when I double click again on that node then, another window is created named as 'Camere_1'. I want to block this. If one window is loaded, then when i double click on the same node, I need to show the old window no need to create a new one, if it is created early. ( check the name in memory)....
Please help me

wysota
20th August 2007, 13:44
See the FAQ (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms).

Michiel
20th August 2007, 14:07
Hi,
I have tree in my program. The nodes in the trees are 'Camera 1', 'Camera 2', 'Camera 3', etc. When I double click on the node 'Camera 1' then a window is created named as 'Camera_1', when I double click on nod 'Camera 2' then a nother window is load named as 'Camera_2' like that.....
My problem is that, When I double click on a node, 'Camera 1' at first time, then a new window is created and load name of that window is 'Camera_1' and when I double click again on that node then, another window is created named as 'Camere_1'. I want to block this. If one window is loaded, then when i double click on the same node, I need to show the old window no need to create a new one, if it is created early. ( check the name in memory)....
Please help me

Looks like you just repeated your question again. Seems like my suggestion would work. Is there something specific about it you don't understand?

sabeesh
20th August 2007, 14:24
Hi,
Can you explain how can i check, if the associated window-pointer is NULL?

Michiel
20th August 2007, 14:36
if (pointer == NULL) {
...
}

sabeesh
20th August 2007, 14:46
Hi,
This is my function, When I double click on a node at that time this function is work,

void CreateCamWindow( QString Name, QString Title ){

CamPanel *Panel = new CamPanel;
Panel->setObjectName(Name);
Panel->setGeometry(QRect(161, 14, 250, 200));
Panel->setWindowTitle(Title);
Panel->show();
}

Here How can I check it? In the variable Name the value come as 'Camera_1'. Then, how can I check the window is loaded?

Michiel
20th August 2007, 14:52
Ok, so you say the names are unique. You could do it this way:


void CreateCamWindow( QString Name, QString Title ) {
static QMap<QString, CamPanel*> panels;

if (!panels.contains(Name)) {
panels.insert(Name, new CamPanel);
}
panels[Name]->setObjectName(Name);
panels[Name]->setGeometry(QRect(161, 14, 250, 200));
panels[Name]->setWindowTitle(Title);
panels[Name]->show();
}

But that's only because I have only seen that one function. There are more elegant ways to do the same.