一,配置并连接数据库
static QSqlDatabase db=QSqlDatabase::addDatabase("QODBC3");
static QSqlQuery query;
db.setHostName("19.87.3.157");
QString dsn="DRIVER={SQL SERVER};SERVER=19.87.3.157;DATABASE=zhao";
db.setDatabaseName(dsn);
db.setUserName("sa");
db.setPassword("ZCX213526");
if (true !=db.open())
{
qDebug()<<db.lastError().text();
}
else
{
qDebug()<<"数据库连接成功.";
}
QObject::connect(timerQuery, SIGNAL(timeout()), this, SLOT(timerQuery_timeout_slot()));
二,设置定时器
//我这里是通过软件start来触发定时器开启
ui->start->setEnabled(false);
ui->disconnect->setEnabled(false);
timerQuery->start(30);//30ms定时
三,取数据解析
void MainWindow::timerQuery_timeout_slot()
{
static uint8_t query_flag = 0;
query.exec("SELECT TOP 1 * FROM uwb_tb WHERE pos IS N