- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不知道为什么 Qt 将这个输出给我。代码编译成功,所有语法格式正确。我曾尝试查看不同的论坛帖子,但无法查明错误。
我目前正在用面包板、电路和灯泡进行测试;所有硬件都正常工作,我能够在 Arduino 软件中捕获电压(如果需要,我可以添加 Arduino 代码)。
我遇到的问题是我无法在 Qt 中显示电压。我正在使用 Arduino Uno 和 Arduino 电压传感器(VCC <25V)。
电压传感器.pro
QT += core gui serialport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = voltage_sensor
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
dialog.cpp
HEADERS += \
dialog.h
FORMS += \
dialog.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QtSerialPort/QSerialPortInfo>
#include <QByteArray>
QT_BEGIN_NAMESPACE
namespace Ui { class Dialog; }
QT_END_NAMESPACE
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = nullptr);
~Dialog();
private slots:
void readSerial();
void updateVoltage(QString);
private:
Ui::Dialog *ui;
QSerialPort *arduino;
static const quint16 arduino_uno_vendor_id = 9025;
static const quint16 arduino_uno_product_id = 67;
QByteArray serialData;
QString serialBuffer;
QString parsed_data;
double voltage_value;
};
#endif // DIALOG_H
#include "dialog.h"
#include "ui_dialog.h"
#include <QSerialPort>
#include <QSerialPortInfo>
#include <string>
#include <QDebug>
#include <QMessageBox>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
ui->voltagelcdNumber->display("-------");
arduino = new QSerialPort(this);
serialBuffer = "";
parsed_data = "";
voltage_value = 0.0;
bool arduino_is_available = false;
QString arduino_uno_port_name;
foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
if(serialPortInfo.hasProductIdentifier() && serialPortInfo.hasVendorIdentifier()){
if((serialPortInfo.productIdentifier() == arduino_uno_product_id) && (serialPortInfo.vendorIdentifier() == arduino_uno_vendor_id)){
arduino_is_available = true;
arduino_uno_port_name = serialPortInfo.portName();
}
}
}
if(arduino_is_available)
{
qDebug()<<"Found the port \n";
arduino->setPortName(arduino_uno_port_name);
arduino->open(QSerialPort::ReadOnly);
arduino->setBaudRate(QSerialPort::Baud9600);
arduino->setDataBits(QSerialPort::Data8);
arduino->setFlowControl(QSerialPort::NoFlowControl);
arduino->setParity(QSerialPort::NoParity);
arduino->setStopBits(QSerialPort::OneStop);
QObject::connect(arduino, SIGNAL(readyRead), this, SLOT(readSerial()));
} else {
qDebug()<<"Could not find the correct port \n";
QMessageBox::information(this,"Serial Port Error", "Could not open the serial port");
}
}
Dialog::~Dialog()
{
if(arduino->isOpen())
{
arduino->close();
}
delete ui;
}
void Dialog::readSerial()
{
QStringList buffer_split = serialBuffer.split(",");
if(buffer_split.length() < 3)
{
serialData = arduino->readAll();
serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
serialData.clear();
} else {
serialBuffer = "";
qDebug() << buffer_split << "\n";
parsed_data = buffer_split[1];
voltage_value = (parsed_data.toDouble()) - 0.1;
qDebug() << "Voltage: " << voltage_value << "\n";
parsed_data = QString::number(voltage_value,'g',4);
Dialog::updateVoltage(parsed_data);
}
}
void Dialog::updateVoltage(QString sensor_reading)
{
ui->voltagelcdNumber->display(sensor_reading);
}
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.setWindowTitle("Voltage Sensor");
w.setFixedSize(434,122);
w.show();
return a.exec();
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>157</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="voltagelabel">
<property name="text">
<string><html><head/><body><p align="center"><span style=" font-size:24pt; font-weight:600; color:#ff0000;">Voltage</span></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="voltagelcdNumber">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>20</green>
<blue>85</blue>
</color>
</brush>
</colorrole>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="128">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="digitCount">
<number>7</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
QObject::connect: Parentheses expected, signal QSerialPort::readyRead in ..\voltage_sensor\dialog.cpp:41
QObject::connect: (receiver name: 'Dialog')
10:56:14: C:/Users/judeb/Desktop/build-voltage_sensor-Desktop_Qt_5_12_6_MinGW_32_bit-Debug/debug/voltage_sensor.exe exited with code 0
最佳答案
现代连接语法通过在编译时检查连接来避免模糊的运行时错误。试试这个:
QObject::connect(arduino, &QSerialPort::readyRead, this, &Dialog::readSerial);
QObject::connect(arduino, SIGNAL(readyRead()), this, SLOT(readSerial()));
关于c++ - QObject::connect: 需要括号,信号 QSerialPort::readyRead in ..\voltage_sensor\dialop.cpp:41,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60530084/
IntelliJ 有没有办法删除周围的括号、括号、引号等?例如,如果我有: "string" 有没有办法删除匹配的引号并得到这个? string 最佳答案 不是直接的,但以下替换表达式(ctrl+R,
我有一段代码是这样的; var x(10); var i = 3; x(i) = 7 document.write("The stored value is " + x(3) +" 这是我正在阅读的书
括号在sql语句中的作用是什么? 例如,在声明中: 插入 table1 ([columnname1], columnname2) 值 (val1, val2) 另外,如果表名在括号中,它会做什么? 最
为什么在“java”中,当你声明“注释”的“参数”时,必须在参数后面放置“一对括号”,注释在语法上与“接口(interface)”形式“非常不同”,所以为什么这很奇怪语法...我知道这与注释是使用幕后
我正在尝试实现后缀到中缀和中缀到后缀(使用堆栈),一切都很顺利,除了当我从后缀转换时我无法想出如何处理括号的想法。它说我必须使用最少数量的括号。例如: ab+c*da-fb-*+ (a+b)*c+
我有这样的数据: $json_data_array = '[ { "id": 1, "value": "hr@test.com",
我有一个字符串,其中包含数字周围的方括号 []。由于此字符串代表我的 SQL 数据库的列名称,因此我需要删除/替换它们。到目前为止,我通过以下方式进行: if (stringWithBracket.C
这是 index.js 文件的代码快照,它是在新的 phonegap 项目中默认创建的。 var app = { // Application Constructor initiali
您好,先生,我正在通过 url 将数组列表 android 发送到 php,它也成功插入,但是 start[ 和 end ] 这个小括号也插入了,我想删除它 我尝试以下代码.. 请告诉我如何删除括号
我正在尝试将 css 括号括在我的 h2 标题周围(大概 90% 都在那里),但我在解决一些小问题时遇到了麻烦: 1. 右边线的间距有点偏,应该拿过来与支架连接。我该如何调整? 和 2. 通过 bg.
有人能给我一些关于这个问题的提示吗:仅当表达式包含正确闭合的圆括号和大括号并且没有其他字符(甚至空格)时,它才是正确的。例如,() ({} () ({})) 是正确的表达式,而 ({)} 不是正确的表
这怎么让宽度变成 100%? .test { width: (50%;); } 我已经知道如何修复它,使其变为 50%,并且该语句或多或少是多余的,我只想知道为什么会发生这种情况。 编辑:ht
请问python的语法本质上df.head()和df.head有什么区别?我可以解释为前一个是用于调用方法,而后一个只是试图获取DataFrame的属性,即头部?我很困惑为什么有时末尾有括号但有时
我通过C#阅读了一些MSDN文档,发现一段代码可以在字符串构造函数和字符串本身之间使用,就像这样 string[] stringname; 这是什么意思呢? 最佳答案 这只是一个数组声明。这意味着st
是否有人知道在创建 PHP 数组时 [ ] 的含义,以及是否真的需要它。因为从我的角度来看。两种方式都够了 方式一,带括号: $cars[] = array ('expensive' => $BMW,
最近我看到了很多将 SQL 值包含在 {} 中的 PHP/MySQL 问题,例如: SELECT * FROM table WHERE field LIKE '{$value}'; 这是怎么回事?它甚
Pattern pattern = Pattern.compile("([a-zA-Z]+)") Matcher matcher = pattern.matcher("Text"); matcher.
这个问题在这里已经有了答案: Usage of string::c_str on temporary string [duplicate] (2 个答案) 关闭 8 年前。 如果我有一个函数 myf
例如, class BasicTransitionFunction(TransitionFunction[GrammarBasedState]): ... 其中TransitionFunc
这个问题在这里已经有了答案: Is short-circuiting logical operators mandated? And evaluation order? (7 个答案) Safety
我是一名优秀的程序员,十分优秀!