what is the exact type of plc and lnx variables?
what is the exact type of plc and lnx variables?
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Exact type of plc and lnx are as follows.
Qt Code:
To copy to clipboard, switch view to plain text mode
Last edited by wysota; 27th January 2010 at 10:20. Reason: Missing [code] tags
What condition ??so is there any method to check the condition
plz go through the below code and before posted code........
Qt Code:
{ if(item == lnx) { ECLogic_Lnx=new eclogic_lnx(main_tab_widget); ECLogic_Lnx->show(); } else if(item == plc) PLCconfig=new plcconfiguration(tab_3); tab_3->setCurrentIndex(main_tab_widget->indexOf(tab_3)); PLCconfig->show(); }To copy to clipboard, switch view to plain text mode
while iam using if(........) condition the other windows(plc,pvc,....)has to open when i click the treewidgetitems like PLC,ECLOGIC-LNX........but the condition is not working correctly
Last edited by wysota; 27th January 2010 at 10:20. Reason: Missing [code] tags
I guess you are messing with the tab bar and tab widget.
PLCconfig->show();
I guess that should be tab_3->show();
or main_tab_widget->show();
I guess you are not showing the parent widget and somehow messing with tab widget.
mkkguru (27th January 2010)
PLCconfig,ECLogic_Lnx are different ui names iam calling that ui's in tab bar and placing in main_tab_widget.,so me facing problem in writing the connections to treewidget,where items like plc,...etc has to click,when we click on plc (QTreewidgetItem) the PLCconfig(ui) has to open,then when we click on ECLOGIC-lnx(QTrreewidgetItem)the ECLogic-LNX(ui)has to open,.............
please kindly go through the code and image(treewidget) which i posted and plz give me the solution.
It is hard to understand what you are saying but your code where you add new tab is wrong. For what do you need new QTabBar?
It should be like this:
Qt Code:
main_tab_widget->insertTab(0, new plcconfiguration(main_tab_widget), "PLC"); main_tab_widget->setCurrentIndex(0);To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Can you finally explain what is a "connection to treewidget"?
You said that now your code is working but it is not working... So can you decide if it is or it is not?
I don't see how your picture can help us understand your problem?
Maybe you can find someone to help you explain your problem in english or use some google translator to help you.
And use CODE tags when pasting code.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
mkkguru (28th January 2010)
Yes, I know, like in every other class.
Yes, I know, you've pasted it before :]do you know below code?
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showPLC(QTreeWidgetItem *)));
Ok, so please run this example and tell me if it is what you want, because I did what I understand you want but as I said, it is difficult to understand your needs.
Qt Code:
#include <QtGui> { Q_OBJECT public: tabWidget->setTabsClosable(true); la->addWidget(treeWidget); la->addWidget(tabWidget); setLayout(la); for (int i = 0; i < 2; ++i) { QTreeWidgetItem *p = new QTreeWidgetItem(treeWidget, QStringList() << QString("parent item %1").arg(i)); for (int j = 0; j < 5; ++j) { QTreeWidgetItem *c = new QTreeWidgetItem(QStringList() << QString("child item %1%2").arg(i).arg(j)); p->addChild(c); } } connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SLOT(slotItemClicked(QTreeWidgetItem*))); connect(tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(slotCloseTab(int))); } private slots: if (w) { tabWidget->setCurrentWidget(w); return; } itemToWidget.insert(item, label); widgetToItem.insert(label, item); label->setAlignment(Qt::AlignCenter); tabWidget->insertTab(0, label, item->text(0)); tabWidget->setCurrentIndex(0); } void slotCloseTab(int index) { itemToWidget.remove(widgetToItem.value(w)); widgetToItem.remove(w); tabWidget->removeTab(index); } private: QTabWidget *tabWidget; QTreeWidget *treeWidget; }; int main(int argc, char **argv) { Widget w; w.show(); return a.exec(); } #include "main.moc"To copy to clipboard, switch view to plain text mode
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
I really hope you make some effort to understand this piece of code and not only copy-paste it to your application.
And next time please try to describe your problem more clearly and attach image which could be helpful, because yours did not even contain any tab widget and we already know how tree widget looks like...
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Hi,
iam attaching my project,u will now understand about my project, plz go through the below ..
1)click on New menu ->new Project window has to open and ECLogic-LNX wil place in Treewidget.then
2)click on ECLogic-LNX->ECLogic-LNX window has to open.
3) click on PLC->PLC configrtn window has to open.
4)click on CPU configuration ->cpu confi window '" " """""""""""""""""""""
5)click on Program variable configuration->Program varbl config "" """"" """"
6)click on IO configuration -> IO Config """"""""""""""""""""'
7)click on BIN ->Bin """"""""""""""""""""""'
But my problem iam getting in my project is when iam clicking on treewidget item all the windows are coming....
plz help to get the solutions of above mention points..
Man, read all answers to your posts once again, ok? It was already mentioned that this is wrong way:
and read about Signals and slots in Qt Assistant and you will know why it is working wrong. There is even a picture showing how it is working.Qt Code:
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showPLC(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showpvc(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showIOC(QTreeWidgetItem*))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showCHNL(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showCPU(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showSLT(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(showBIN(QTreeWidgetItem *))); connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem* ,int)),this,SLOT(showItem(QTreeWidgetItem*)));To copy to clipboard, switch view to plain text mode
And the solution has already been given to you in previous posts.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
mkkguru (28th January 2010)
Hi faldzip,
I tried the previous post code ,which i used the single slot,there i written like below
but above condition is not working for me,can you please solve how to write that code......Qt Code:
{ if(item=="PLC") { PLCconfig=new plcconfiguration(); main_tab_widget->insertTab(0,PLCconfig, "PLC"); main_tab_widget->setCurrentIndex(0); PLCconfig->show(); } else if(item==lnx) { ECLogic_Lnx=new eclogic_lnx(main_tab_widget); ECLogic_Lnx->show(); } }To copy to clipboard, switch view to plain text mode
Last edited by wysota; 28th January 2010 at 20:14. Reason: Missing [code] tags
What is the type of item and what is the type of "PLC"?
And in your code lnx is a local variable in different method so how do you want to reference it in this method?
I think you need to revise your C++ knowledge...
Why can't you use QTreeWidgetItem methods like for example text() to get know what item did you clicked?
You can event set your data with QTreeWidgetItem::setData() with Qt::UserRole while creating item to let you know what item it is.
Qt Code:
lnx->setData(0, Qt::UserRole, "lnx"); // and check it: if (item->data().toString() == "lnx")To copy to clipboard, switch view to plain text mode
P.S. And use CODE tags for pasting code! Your code is already a mess in terms of formatting and without CODE tags it is even worse.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
mkkguru (28th January 2010)
Hi,
I didnt mention any type to Item and PLC ,i just created as QTreewidgetItem *item and QTreeWidgetItem *plc ,please go through my attached project in previous post ,let me know what i done the mistakes in code,as iam new to Qt,this is the first project iam handling ,please feel free to answer to my post .
thankq ..
I mean C++ type... To make you things easier I can say that in this code:
item's type is QTreeWidgetItem* and "PLC" is const char *, so both are pointers. Do you want to compare two memory addresses of two completely different things? I don't think so...Qt Code:
{ if(item=="PLC") { PLCconfig=new plcconfiguration(); main_tab_widget->insertTab(0,PLCconfig, "PLC"); main_tab_widget->setCurrentIndex(0); PLCconfig->show(); } else if(item==lnx) { ECLogic_Lnx=new eclogic_lnx(main_tab_widget); ECLogic_Lnx->show(); } }To copy to clipboard, switch view to plain text mode
And again:
You have created them in another method as local variables so they not exist where you want to reference them. They are dead :]i just created as QTreewidgetItem *item and QTreeWidgetItem *plc
Your problem now is pure C++ issue. Please revise your C++ basics, like local variables, scopes, referencing pointers and so on.
And your project your slot showItem looks:
Which does not make sense at all.Qt Code:
{ ECLogic_Lnx=new eclogic_lnx(main_tab_widget); ECLogic_Lnx->show(); QStringList item; item << "PLC" << "CPU CONFIGURATION" << "PROGRAM VARIABLE CONFIGURATION" << "IO CONFIGURATION" << "BIN" << "SLOT" <<"LADDER PROGRAM"; if(item=="PLC") { PLCconfig=new plcconfiguration(); main_tab_widget->insertTab(0,PLCconfig, "PLC"); main_tab_widget->setCurrentIndex(0); PLCconfig->show(); } else if(item==lnx) { ECLogic_Lnx=new eclogic_lnx(main_tab_widget); ECLogic_Lnx->show(); } }To copy to clipboard, switch view to plain text mode
EDIT:
Oops now I found that there is another lnx variable which is class member - that would be better, but when you are creating new QTreeWidgetItem you are assigning it to the local variable with the same name (lnx) so your member variable lnx is always unassigned and referencing it will cause segmentation fault.
Last edited by faldzip; 28th January 2010 at 16:04.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
mkkguru (30th January 2010)
mkkguru (30th January 2010)
Bookmarks