示例#1
0
void Dialog::startServer() {

    if (!_serv.isNull())
        _serv.clear();
    _serv = QSharedPointer<PollsServer>(new PollsServer(this));
    connect(_serv.data(), SIGNAL(addLogToGui(QString,QColor)), this, SLOT(onAddLogToGui(QString,QColor)));

    auto ip = ui->leHost->text();
    auto port = ui->lePort->text();

    QHostAddress addr;
    if (!addr.setAddress(ip))
    {
        addToLog(" invalid address " + ip, Qt::darkRed);
        return;
    }

    if (_serv->doStartServer(addr, port.toInt()))
    {
        addToLog(" server started at " + ip + ":" + port, Qt::darkGreen);
        ui->pbStartStop->setText("Stop server");
    }
    else
    {
        addToLog(" server not started at " + ip + ":" + port, Qt::darkRed);
        ui->pbStartStop->setChecked(true);
    }
}
示例#2
0
void Dialog::onVoteUp(QString category, QString code, QString filename) {
    _votes.insert(code, filename);

    if(!_usedCodes.contains(code))
        _usedCodes.insert(code, QVector<QString>());

    if (!_usedCodes[code].contains(category))
        _usedCodes[code].push_back(category);

    onAddLogToGui("Vote " + category + " " + code + " " + filename, Qt::yellow);

    QTextStream log(&_logFile);
    log << code << " " << filename << "\n";
    _logFile.flush();
}
示例#3
0
Dialog::Dialog(QWidget *parent) :QDialog(parent), ui(new Ui::Dialog)
{
    ui->setupUi(this);

    //создаем сервер
    _serv = new MyServer(this, this);

    //подключаем сигналы от виджета к серверу
    connect(this, SIGNAL(messageFromGui(QString,QStringList)), _serv, SLOT(onMessageFromGui(QString,QStringList)));
    connect(_serv, SIGNAL(addLogToGui(QString,QColor)), this, SLOT(onAddLogToGui(QString,QColor)));

    //по умолчанию запускаем сервер на 127.0.0.1:1234
    if (_serv->doStartServer(QHostAddress::LocalHost, 1234))
    {
        ui->lwLog->insertItem(0, QTime::currentTime().toString()+" server strated at "+_serv->serverAddress().toString()+":"+QString::number(_serv->serverPort()));
        ui->lwLog->item(0)->setTextColor(Qt::green);
    }
    else
    {
        ui->lwLog->insertItem(0, QTime::currentTime().toString()+" server not strated at "+_serv->serverAddress().toString()+":"+QString::number(_serv->serverPort()));
        ui->lwLog->item(0)->setTextColor(Qt::red);
        ui->pbStartStop->setChecked(true);
    }
}