Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Quoted
Originally posted by anda_skoa
You don't necessarily have to use QThread+QSocketDevice.
If your data transfer needs are not huge, you can use QSocket, which works through the event loop
Cheers,
_
Quoted
Originally posted by mss
Really?

Quoted
This might seem as a really bad question, but when I want to disconnect from 1 certain server (from a list), is there a way for me to do so?
Quoted
And maybe send a command to all the servers I am connected to?

Quoted
Or is it then easier to use QSocketDevice and Threads?

Quoted
Originally posted by mss
How can I loop through the list? Could you show me an example ? :-)
Quoted
In the GUI-constructor I instantiate the connection-class, and connect the signals/slots to that, but should I then do the same in the connection class? (Instantiate the GUI-class).
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// GUI header:
public slots:
void socketClosed();
void updateView(QString data);
void socketConnected();
// GUI Class
Client *cl = new Client();
connect(cl, SIGNAL(dataRcvd(QString)), this, SLOT(updateView(QString)));
connect(cl, SIGNAL(sckClosed()), this, SLOT(socketClosed()));
connect(cl, SIGNAL(sckConnected()), this, SLOT(socketConnected()));
void Gui::socketConnected()
{
printf("Signal Emitted?"); // Doesnt happen
}
//Client header
signals:
void dataRcvd(QString data);
void sckClosed();
void sckConnected();
//Client Class:
void Client::test()
{
printf("Testing testing"); // This gets printed
emit sckConnected(); // this does not trigger anything in the GUI class.
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// First the Gui header
class Gui : public QVBox
{
Q_OBJECT
public:
Gui(QWidget *parent = 0, const char *name = 0);
~Gui();
(....)
};
//and then the Client header:
class Client : public QVBox
{
Q_OBJECT
public:
Client();
~Client();
(...)
}
|
|
|
Source code |
1 2 3 4 5 |
void Gui::doConnect()
{
list.append(new Client(ip, port, "ServerName"));
infoText->append( tr("Connecting to:" +qleIP->text()) );
}
|