我正在尝试使用QXmpp向我的应用程序添加MUC功能,我在QXmppMucManager.h头文件中关注此信息
/// \brief The QXmppMucManager class makes it possible to interact with
/// multi-user chat rooms as defined by XEP-0045: Multi-User Chat.
///
/// To make use of this manager, you need to instantiate it and load it into
/// the QXmppClient instance as follows:
///
/// \code
/// QXmppMucManager *manager = new QXmppMucManager;
/// client->addExtension(manager);
/// \endcode
///
/// You can then join a room as follows:
///
/// \code
/// QXmppMucRoom *room = manager->addRoom("room@conference.example.com");
/// room->setNickName("mynick");
/// room->join();
/// \endcode
///
/// \ingroup Managers
在我的一个类的构造函数中,我正在添加像这样的MuCManager
QXmppMucManager *manager = new QXmppMucManager;
m_xmppClient.addExtension(manager);
并在一个创建Muc组的插槽中我正在做这个
QXmppMucRoom *room = manager->addRoom("livefit@mthinkpad");
room->setNickName("mThinkpad");
room->join();
我希望这可以创建一个房间并加入,如果它不存在并加入,如果它已经存在但它只是崩溃我的应用程序。我无法围绕qxmpp如何实现xep - 0045.I如果有人帮我指出我做错了什么或者如何从我的客户端在我的服务器上创建一个Muc房间,我将不胜感激。 我的服务器是本地ejabberd安装,我可以在“mthinkpad”域访问它。
答案 0 :(得分:0)
如果有人遇到同样的问题,我可以创建房间。这是代码。这是我动态创建和配置房间(我正在使用Openfire并允许它)但你可以请求如果你想要的配置表格。
String jid=roomName.text()+"@conference."+serverName;
if(jid.isEmpty())
return ;
QList<QXmppMucRoom*> rooms = manager->rooms();
QXmppMucRoom* r;
foreach(r, rooms)
{
if(r->jid() == jid)
{
//LOG_MODEL_DEBUG("Group chat", "had joined room[%s]", qPrintable(jid));
return ;
}
}
m_pRoom = manager->addRoom(jid);
if(m_pRoom)
{
//nick
m_pRoom->setNickName("theDip");
//join the room.
m_pRoom->join();
}
//Prepare the dataform.
QXmppDataForm form(QXmppDataForm::Submit);
QList<QXmppDataForm::Field> fields;
{
QXmppDataForm::Field field(QXmppDataForm::Field::HiddenField);
field.setKey("FORM_TYPE");
field.setValue("http://jabber.org/protocol/muc#roomconfig");
fields.append(field);
}
QXmppDataForm::Field field;
field.setKey("muc#roomconfig_roomname");
field.setValue(roomName.text());
fields.append(field);
field.setKey("muc#roomconfig_subject");
field.setValue(roomSubject.text());
fields.append(field);
field.setKey("muc#roomconfig_roomdesc");
field.setValue(roomDesc.text());
fields.append(field);
{
QXmppDataForm::Field field(QXmppDataForm::Field::BooleanField);
field.setKey("muc#roomconfig_persistentroom");
field.setValue(true);
fields.append(field);
}
form.setFields(fields);
//The dataform ends here.
m_pRoom->setConfiguration(form);