Hi,

Originally Posted by
wysota
The nature of the warning message you get implies that you're probably using a separate thread somewhere. Are you sure you need it, because I don't think so...
No, there's no other Thread.

Originally Posted by
wysota
About the error itself, it's hard to say anything without seeing more code. As you are using QTreeWidget and not QTreeView, you shouldn't access model indexes yourself, so I take it that you got that message from some internal Qt code or did you use QModelIndex somewhere?
I've created the MainWindow with designer and I must admit, that using of QTreeWidget insteand of QTreeView was a coincidence, because I don't really know what's the difference between these widgets.
And no, I'm not using QModelIndex anywhere.
Your request for more code, well, there isn't much more. As said above I created the MainWindow with designer, so my MainWindow-Class is:
{
private Ui_MainWindow ui = new Ui_MainWindow();
private JJabRoster roster;
private XMPPConnection con;
public MainWindow()
{
ui.setupUi(this);
try
{
con = new XMPPConnection("macht-locker.de");
con.login("hanf", "password");
}
catch(XMPPException e)
{
System.err.println("Error: "+e.getMessage());
System.exit(1);
}
roster = new JJabRoster(con, ui.rosterTree,
ui.actionHide_empty_Groups.isChecked(), ui.actionHide_Offline_Contacts.isChecked());
ui.actionHide_Offline_Contacts.toggled.connect(roster,"toggleHideOfflineContacts(boolean)");
ui.actionHide_empty_Groups.toggled.connect(roster,"toggleHideEmptyGroups(boolean)");
ui.rosterTree.itemDoubleClicked.connect(roster, "createChat(int)");
}
}
public class MainWindow extends QMainWindow
{
private Ui_MainWindow ui = new Ui_MainWindow();
private JJabRoster roster;
private XMPPConnection con;
public MainWindow()
{
ui.setupUi(this);
try
{
con = new XMPPConnection("macht-locker.de");
con.login("hanf", "password");
}
catch(XMPPException e)
{
System.err.println("Error: "+e.getMessage());
System.exit(1);
}
roster = new JJabRoster(con, ui.rosterTree,
ui.actionHide_empty_Groups.isChecked(), ui.actionHide_Offline_Contacts.isChecked());
ui.actionHide_Offline_Contacts.toggled.connect(roster,"toggleHideOfflineContacts(boolean)");
ui.actionHide_empty_Groups.toggled.connect(roster,"toggleHideEmptyGroups(boolean)");
ui.rosterTree.itemDoubleClicked.connect(roster, "createChat(int)");
}
}
To copy to clipboard, switch view to plain text mode
And the JJabRoster-Class:
public class JJabRoster extends
QObject {
private LinkedList<RosterGroup> groups;
private XMPPConnection con;
private Roster roster;
private boolean hideEmptyGroups;
private boolean hideOfflineContacts;
public JJabRoster
(XMPPConnection con,
QTreeWidget tree, boolean hideEmptyGroups, boolean hideOfflineContacts
) {
this.tree = tree;
this.con = con;
this.roster = con.getRoster();
this.roster.addRosterListener(new RosterListener() {
public void rosterModified(Collection addresses)
{
System.out.println("roster modified: "+addresses.toString());
}
public void presenceChanged(String user)
{
parent.setText(0, user);
getTree().addTopLevelItem(parent);
System.out.println(user);
}
public void entriesUpdated(Collection addresses)
{
System.out.println("entries updated: "+addresses.toString());
}
public void entriesDeleted(Collection addresses)
{
System.out.println("entries deleted: "+addresses.toString());
}
public void entriesAdded(Collection addresses)
{
System.out.println("entries added: "+addresses.toString());
}
});
this.hideEmptyGroups = hideEmptyGroups;
this.hideOfflineContacts = hideOfflineContacts;
groups = new LinkedList<RosterGroup>();
for(Iterator<RosterGroup> it = roster.getGroups();it.hasNext();)
groups.add(it.next());
}
public LinkedList<RosterGroup> getGroups()
{
return groups;
}
public List<RosterEntry> getEntriesForGroup(RosterGroup group)
{
LinkedList<RosterEntry> list = new LinkedList<RosterEntry>();
for(Iterator<RosterEntry> it = group.getEntries(); it.hasNext();)
list.add(it.next());
return list;
}
public void toggleHideEmptyGroups(boolean hide)
{
this.hideEmptyGroups = hide;
}
public void toggleHideOfflineContacts(boolean hide)
{
this.hideOfflineContacts = hide;
}
public Roster getRoster()
{
return roster;
}
{
return tree;
}
}
public class JJabRoster extends QObject
{
private LinkedList<RosterGroup> groups;
private QTreeWidget tree;
private XMPPConnection con;
private Roster roster;
private boolean hideEmptyGroups;
private boolean hideOfflineContacts;
public JJabRoster(XMPPConnection con, QTreeWidget tree, boolean hideEmptyGroups, boolean hideOfflineContacts)
{
this.tree = tree;
this.con = con;
this.roster = con.getRoster();
this.roster.addRosterListener(new RosterListener() {
public void rosterModified(Collection addresses)
{
System.out.println("roster modified: "+addresses.toString());
}
public void presenceChanged(String user)
{
QTreeWidgetItem parent = new QTreeWidgetItem();
parent.setText(0, user);
getTree().addTopLevelItem(parent);
System.out.println(user);
}
public void entriesUpdated(Collection addresses)
{
System.out.println("entries updated: "+addresses.toString());
}
public void entriesDeleted(Collection addresses)
{
System.out.println("entries deleted: "+addresses.toString());
}
public void entriesAdded(Collection addresses)
{
System.out.println("entries added: "+addresses.toString());
}
});
this.hideEmptyGroups = hideEmptyGroups;
this.hideOfflineContacts = hideOfflineContacts;
groups = new LinkedList<RosterGroup>();
for(Iterator<RosterGroup> it = roster.getGroups();it.hasNext();)
groups.add(it.next());
}
public LinkedList<RosterGroup> getGroups()
{
return groups;
}
public List<RosterEntry> getEntriesForGroup(RosterGroup group)
{
LinkedList<RosterEntry> list = new LinkedList<RosterEntry>();
for(Iterator<RosterEntry> it = group.getEntries(); it.hasNext();)
list.add(it.next());
return list;
}
public void toggleHideEmptyGroups(boolean hide)
{
this.hideEmptyGroups = hide;
}
public void toggleHideOfflineContacts(boolean hide)
{
this.hideOfflineContacts = hide;
}
public Roster getRoster()
{
return roster;
}
public QTreeWidget getTree()
{
return tree;
}
}
To copy to clipboard, switch view to plain text mode
And to be complete my JJabRosterEntry-Class:
{
private RosterEntry entry;
{
super(parent);
this.entry = entry;
String bareJID = StringUtils.parseBareAddress(entry.getUser());
try
{
this.setText(0,entry.getName());
}
catch(NullPointerException e)
{
this.setText(0, bareJID);
}
this.setToolTip(0, entry.getUser());
}
public RosterEntry getEntry() {
return entry;
}
}
public class JJabRosterEntry extends QTreeWidgetItem
{
private RosterEntry entry;
public JJabRosterEntry(QTreeWidgetItem parent, RosterEntry entry)
{
super(parent);
this.entry = entry;
String bareJID = StringUtils.parseBareAddress(entry.getUser());
try
{
this.setText(0,entry.getName());
}
catch(NullPointerException e)
{
this.setText(0, bareJID);
}
this.setToolTip(0, entry.getUser());
}
public RosterEntry getEntry() {
return entry;
}
}
To copy to clipboard, switch view to plain text mode
Greets,
Ace
Bookmarks