예제 #1
0
Sender::Sender(QWidget *parent)
    : QWidget(parent)
{
    statusLabel = new QLabel(tr("Ready to broadcast datagrams on port 45454"));
    statusLabel->setWordWrap(true);

    startButton = new QPushButton(tr("&Start"));
    quitButton = new QPushButton(tr("&Quit"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(startButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);

    timer = new QTimer(this);
//! [0]
    udpSocket = new QUdpSocket(this);
//! [0]
    messageNo = 1;

    connect(startButton, SIGNAL(clicked()), this, SLOT(startBroadcasting()));
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(statusLabel);
    mainLayout->addWidget(buttonBox);
    setLayout(mainLayout);

    setWindowTitle(tr("Broadcast Sender"));
}
예제 #2
0
파일: sender.cpp 프로젝트: hkutangyu/QTDemo
Sender::Sender(QObject *parent)
	: QObject(parent)
{
	timer = new QTimer(this);
	udpSocket = new QUdpSocket(this);
	messageNo = 1;
	connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));
}
예제 #3
0
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    timer = new QTimer();
    udpSocket = new QUdpSocket(this);
    host = new QHostAddress("127.0.0.1");

    udpSocketFromQGroundControl = new QUdpSocket(this);
    udpSocketFromQGroundControl->bind(14551);//, QUdpSocket::ShareAddress);

    //connect(ui->pbStartSimuMavlink,SIGNAL(clicked()),this,SLOT(startBroadcasting()));
    connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));
    connect(udpSocketFromQGroundControl, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));

}
예제 #4
0
Dialog::Dialog(QWidget *parent)
    : QWidget(parent)
{
    statusLabel = new QLabel;
    statusLabel->setWordWrap(true);
    quitButton = new QPushButton(tr("&Quit"));
    quitButton->setAutoDefault(false);
    startButton = new QPushButton(tr("&Start"));
    startButton->setEnabled(true);
    startButton->setDefault(true);
    stopButton = new QPushButton(tr("&Stop"));
    stopButton->setEnabled(false);
    stopButton->setDefault(true);

    timer = new QTimer(this);
//! [0]
    udpSocket = new QUdpSocket(this);
//! [0]
    messageNo = 1;
    if (!server.listen()) {
        QMessageBox::critical(this, tr("MOGA computing Server"),
                              tr("Unable to start the server: %1.")
                              .arg(server.errorString()));
        close();
        return;
    }
    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
            ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }
    // if we did not find one, use IPv4 localhost
    if (ipAddress.isEmpty())
        ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
    statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n"
                            "Run the MOGA optimizatioin now.")
                         .arg(ipAddress).arg(server.serverPort()));


    connect(startButton, SIGNAL(clicked()), this, SLOT(start_server()));
    connect(stopButton, SIGNAL(clicked()), this, SLOT(stop_server()));
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    //connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));
    connect(timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(quitButton);
    buttonLayout->addWidget(startButton);
    buttonLayout->addWidget(stopButton);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(statusLabel);
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);
    setWindowTitle(tr("MOGA parallel computing Server"));
}