我这个功能是双击某个用户,打开该用户设置的共享目录,所以,双击的时候,先用你刚刚说得第一种方案去getaddress取回该用户的ip,想当双击后,将该用户的ip传给showshare.cpp这样才能在showshare里显示该用户的共享目录。开始我以为是由于showshare还没打开就连接它的槽,所以地址越界,才报错,但是上面负责服务器端和客户机端通行的 ClientSocket ;
(ClientSocket client; //一个Socket类)它在ZzWorldClient.cpp也connect很多个,也没事啊!
void ZzWorldClient::makeConnections()
{
connect(sendPushButton,SIGNAL(clicked()),
this,SLOT(sendMessage())); //1 2
connect(&client,SIGNAL(connected()),
this,SLOT(showConnectedInLabel()));
connect(&client,SIGNAL(connected()),
this,SLOT(showuser()));
connect(&client,SIGNAL(disconnected()),
this,SLOT(showDisconnectedInLabel()));
connect(&client,SIGNAL(addNewComerToNameList(const QString &,const QHostAddress &)),
this,SLOT(addNewComerToNameList(const QString &,const QHostAddress &)));
connect(&client,SIGNAL(showMessageInTextEdit(const QString &,const QString &,const QString &)),
this,SLOT(showMessageInTextEdit(const QString &,const QString &,const QString &)));//3 4
connect(&client,SIGNAL(nameAndPasswordIsRight()),
this,SLOT(nameAndPasswordIsRight()));
connect(&client,SIGNAL(nameAndPasswordIsNotRight()),
this,SLOT(nameAndPasswordIsNotRight()));
connect(&client,SIGNAL(removeLeaverNameFromNameList(const QString &)),
this,SLOT(removeLeaverNameFromNameList(const QString &)));
connect(&client,SIGNAL(registerSuccess()),
this,SLOT(registerSuccess()));
connect(&client,SIGNAL(registerFailed()),
this,SLOT(registerFailed()));
connect(&client,SIGNAL(getaddress(const QString &)),this,SLOT(getaddress(const QString &)));
connect(nameListView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(getuseraddress()));
connect(this,SIGNAL(sendAddress(const QString &)),showshareDialog,SLOT(sendAddress(const QString &)));
后来把写成这样:
showshareDialog=new showshare(this);
showshareDialog->show();
label2->setText(address);
connect(this,SIGNAL(sendAddress(const QString &)),showshareDialog,SLOT(sendAddress(const QString &)));
emit sendAddress(address);
这次 connect(this,SIGNAL(sendAddress(const QString &)),showshareDialog,SLOT(sendAddress(const QString &)));这行没报错了,但是 emit sendAddress(address);
报错。
系统是好的,我试过在showshare里制定个ip给它,显示都正常,现在时ip传不过去。郁闷的!!!!