setupUi() is automatically generated, don't change it because next time you run uic on the .ui file your changes will be overwritten. Initialize the private member in class constructor.
setupUi() is automatically generated, don't change it because next time you run uic on the .ui file your changes will be overwritten. Initialize the private member in class constructor.
No , this time also the same thing continues. The selected item is removed but not added to the other list.
As suggested, i changed here:
Qt Code:
: m_messageListWidget(0), m_statusLabel(0), m_layout(0), m_maxRecent(maxRecent), m_service(new QMessageService(this)), m_state(Unloaded) { setupUi(); spm = new Spam_MessagesWidget(this, SpamMessagesCount); // I added here [initialization] connect(m_service,SIGNAL(messagesFound(const QMessageIdList&)),this,SLOT(messagesFound(const QMessageIdList&))); connect(m_service,SIGNAL(stateChanged(QMessageService::State)),this,SLOT(stateChanged(QMessageService::State))); //register for message update notifications connect(&m_manager, SIGNAL(messageUpdated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)), this, SLOT(messageUpdated(const QMessageId&, const QMessageManager::NotificationFilterIdSet&))); connect(&m_manager, SIGNAL(messageRemoved(const QMessageId&, const QMessageManager::NotificationFilterIdSet&)), this, SLOT(messageRemoved(const QMessageId&, const QMessageManager::NotificationFilterIdSet&))); m_storeFilterId = m_manager.registerNotificationFilter(QMessageFilter::byStandardFolder(QMessage::InboxFolder)); }To copy to clipboard, switch view to plain text mode
maybe show us Spam_MessagesWidget::additemS code.
Here it goes:
Qt Code:
{ m_messageListWidget->insertItem(0,temp); m_messageListWidget->update(); }To copy to clipboard, switch view to plain text mode
You never call setLayout(m_layout) after creating layout objects, try to call this->setLayout(m_layout); after preparing ui elements.
Still No Effect...!! I guess the function additemS() is not getting called from the RecentMessagesWidget class. I don't understand why the friend class function is not being called from here.
I am looking for a simple working example using friend classes or friend function that can update on the private members of both the classes. I started with this simple example.
I guess the sole problem is here:
I am posing the problem in a different form:
Qt Code:
//File recentmessageswidget.h [A simple class Containing 2 listwidgets] { Q_OBJECT public: ~RecentMessagesWidget(); public: QListWidget* I_messageListWidget; QListWidget* S_messageListWidget; public slots: void processResults(); void reportAsSpam(); }; //recentmessageswidget.cpp #include "recentmessageswidget.h" { processResults(); } RecentMessagesWidget::~RecentMessagesWidget() { } void RecentMessagesWidget::processResults() { //I_messageListWidget = new QListWidget(this); //S_messageListWidget = new QListWidget(this); } void RecentMessagesWidget :: reportAsSpam() { int cr = I_messageListWidget->currentRow(); //I_messageListWidget->update(); //S_messageListWidget = new QListWidget(this); S_messageListWidget->insertItem(0,temp); // PROBLEM is here... S_messageListWidget->update(); I_messageListWidget->update(); } //In file tabmain.h { Q_OBJECT public: ~TabMain(); private: void buildTabMenuBar(int index); signals: public slots: void activeTabChanged(int index); private: QTabWidget* tabWidget; }; { Q_OBJECT public: ~InBoxTab(); void setupUi(); public slots: void hello(); void rspam(); private: RecentMessagesWidget* m_recentMessagesWidget; }; { Q_OBJECT public: ~SpamBoxTab(); void setupUi(); public slots: void hello(); private: RecentMessagesWidget* sm_recentMessagesWidget; }; { setContextMenuPolicy(Qt::NoContextMenu); this->setWindowTitle("SMSAssassin Alpha"); tabWidget->setContextMenuPolicy(Qt::NoContextMenu); InBoxTab* widget1 = new InBoxTab(); tabWidget->addTab(widget1, " INBOX "); SpamBoxTab* widget2 = new SpamBoxTab(); tabWidget->addTab(widget2, " SPAMBOX "); //adda(); setCentralWidget(tabWidget); #ifdef Q_OS_SYMBIAN foreach(w,widgets) { w->setContextMenuPolicy(Qt::NoContextMenu); } #endif } TabMain::~TabMain() { } void TabMain::activeTabChanged(int index) { buildTabMenuBar(index); } void TabMain::buildTabMenuBar(int index) { menubar->clear(); switch(index) { case 0: { menubar -> addAction("Inbox user Menu", tabWidget->widget(index),SLOT( hello() ) ); menubar -> addAction("Report as Spam", tabWidget->widget(index), SLOT( rspam() ) ); break; } case 1: { menubar -> addAction("SpamBox user Menu", tabWidget->widget(index), SLOT(hello()) ); break; } default: { break; } } } m_recentMessagesWidget(0) { setupUi(); } InBoxTab:: ~InBoxTab() { } void InBoxTab::setupUi() { m_recentMessagesWidget = new RecentMessagesWidget(this); vbl->addWidget(m_recentMessagesWidget->I_messageListWidget); this->setLayout(vbl); } void InBoxTab :: rspam() { m_recentMessagesWidget->reportAsSpam(); } void InBoxTab::hello() { messageBox->exec(); delete messageBox; messageBox = 0; } { setupUi(); } void SpamBoxTab::setupUi() { sm_recentMessagesWidget = new RecentMessagesWidget(this); vbl->addWidget(sm_recentMessagesWidget->S_messageListWidget); this->setLayout(vbl); } SpamBoxTab::~SpamBoxTab() { } void SpamBoxTab::hello() { messageBox->exec(); delete messageBox; messageBox = 0; }To copy to clipboard, switch view to plain text mode
The problem is same, item is removed from one tab but not gets added to other tab.
Attached is a very minimalist example of two listWidgets that shows that the code you think is problematic, is actually working. I don't know where and why there is an error in your program but you have to look for it somewhere else.
In my case the problem is that on selection the item is removed from one Listwidget of one TAB but doesn't get added in other TAB.
May be my problem is due to the TAB thing. Attached is my project, You can check it, It doesn't work but doesn't throws any error too.
Besides your title and I don't see anywhere in your code to be declared a friend (as in C++ friend) class.
Your main widget is a tabBar that creates InBoxTar and SpamBoxTab both of type RecentMessageWidget. Now, in the RecentMessageWidget's constructor there are created two list widget (I_.. and S_...)
So what you have is
Tabbar----InBoxTab------RecentMessageWidget's ---I_messageListWidget (1)+S_messageListWidget (2)
Tabbar----SpamBoxTab---RecentMessageWidget's---I_messageListWidget (3)+S_messageListWidget (4)
(2) and (3) are invisible because they are not added in the layout, but does not mean they don't exist. What you are doing is a connection between (1) and (2), though what you want is a connection between (1) and (4) which simply exist in different objects.
My suggestion: Create only one listWidget. Maybe it's better RecentMessage to be a subclass of QListWidget. Add a method that returns the currentItem, and a method that reports this QListWidgetItem.
So in your tabBar class you can call something likeQt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
spamBox->reportAsSpam(inBox->getCurrentItem());To copy to clipboard, switch view to plain text mode
Friend is in my original code which is in my first thread. Initially, i thought my problem is due to friend class.
And, Why i want to keep 2 listwidgets is that i wish to maintain 2 different lists containing different items in 2 tabs.
Bookmarks