本文整理汇总了C++中QSerialPort::dataBits方法的典型用法代码示例。如果您正苦于以下问题:C++ QSerialPort::dataBits方法的具体用法?C++ QSerialPort::dataBits怎么用?C++ QSerialPort::dataBits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSerialPort
的用法示例。
在下文中一共展示了QSerialPort::dataBits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPortSettings
PortSettings PositioningMethodSerialPortOptions::getPortSettings(const QString &APortName)
{
PortSettings portSettings;
OptionsNode node;
if (Options::hasNode(OPV_POSITIONING_METHOD_SERIALPORT, APortName))
node = Options::node(OPV_POSITIONING_METHOD_SERIALPORT, APortName);
else
{
QSerialPort *serialPort = new QSerialPort(APortName);
if (serialPort->open(QIODevice::ReadOnly))
{
portSettings.FBaudRate = serialPort->baudRate();
portSettings.FDataBits = serialPort->dataBits();
portSettings.FStopBits = serialPort->stopBits();
portSettings.FParity = serialPort->parity();
portSettings.FFlowControl = serialPort->flowControl();
serialPort->close();
}
else // Failed to open the port
node = Options::node(OPV_POSITIONING_METHOD_SERIALPORT, APortName);
serialPort->deleteLater();
}
if (!node.isNull())
{
portSettings.FBaudRate = node.value("baud-rate").toLongLong();
portSettings.FDataBits = (QSerialPort::DataBits)node.value("data-bits").toInt();
portSettings.FStopBits = (QSerialPort::StopBits)node.value("stop-bits").toInt();
portSettings.FParity = (QSerialPort::Parity)node.value("parity").toInt();
portSettings.FFlowControl = (QSerialPort::FlowControl)node.value("flow-control").toInt();
}
return portSettings;
}
示例2: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qRegisterMetaType<eegDataType::iterator>("eegDataType::iterator");
/// server
ui->serverPortSpinBox->setMaximum(65535);
int hostCounter = 0;
ui->serverAddressComboBox->addItem("local, 120");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("127.0.0.1:120"));
ui->serverAddressComboBox->addItem("local, home");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("127.0.0.1:35577"));
ui->serverAddressComboBox->addItem("Enceph");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("213.145.47.104:120"));
ui->serverAddressComboBox->addItem("pew");
ui->serverAddressComboBox->setItemData(hostCounter++,
QVariant("192.168.0.104:120"));
connect(ui->serverAddressComboBox, SIGNAL(highlighted(int)),
this, SLOT(serverAddressSlot(int)));
connect(ui->serverAddressComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(serverAddressSlot(int)));
#if MY_LINROWS
ui->serverAddressComboBox->setCurrentText("pew");
#else
ui->serverAddressComboBox->setCurrentText("Enceph");
#endif
// ui->serverAddressComboBox->setCurrentText("pew"); /// fix via router, always 192.168.0.104
/// com
for(int i = 0; i < 9; ++i)
{
ui->comPortComboBox->addItem("COM"+QString::number(i+1));
}
ui->comPortComboBox->setCurrentText("COM5");
#if COM_IN_MAIN
connect(ui->connectComPortPushButton, SIGNAL(clicked()),
this, SLOT(comPortSlot()));
comPort = new QSerialPort(this);
connect(comPort, SIGNAL(error(QSerialPort::SerialPortError)),
this, SLOT(serialPortErrorSlot(QSerialPort::SerialPortError)));
connect(this->ui->comPortSendOnePushButton, SIGNAL(clicked()),
this, SLOT(sendOne()));
connect(this->ui->comPortSendTwoPushButton, SIGNAL(clicked()),
this, SLOT(sendTwo()));
#endif
#if 0
/// COM test
QSerialPort * comPort;
comPort = new QSerialPort(this);
comPort->setPortName(ui->comPortComboBox->currentText());
comPort->open(QIODevice::WriteOnly);
if(comPort->isOpen())
{
// cout << comPort->errorString() << endl;
cout << "serialPort opened: " + def::comPortName << endl;
cout << "portName: " << comPort->portName().toStdString() << endl;
cout << "dataBits: " << comPort->dataBits() << endl;
cout << "baudRate: " << comPort->baudRate() << endl;
cout << "dataTerminalReady: " << comPort->isDataTerminalReady() << endl;
cout << "flowControl: " << comPort->flowControl() << endl;
cout << "requestToSend: " << comPort->isRequestToSend() << endl;
cout << "stopBits: " << comPort->stopBits() << endl << endl;
}
comPortDataStream.setDevice(comPort);
#endif
/// socket
#if SOCKET_IN_MAIN
socket = new QTcpSocket(this);
#endif
#if !DATA_READER
socketDataStream.setDevice(socket);
socketDataStream.setByteOrder(QDataStream::LittleEndian); // least significant bytes first
#endif
#if SOCKET_IN_MAIN
//.........这里部分代码省略.........