我使用缓冲区从串口接收数据.缓冲区的固定长度为100,当我收到数据时,我将这个数据的长度存储在一个变量(索引)中.
我想检查从0到索引1的缓冲区是否包含子字符串.
我已经读过,我可以使用strstr和strdup来完成它,但我有两个问题.首先,我不知道如何从缓冲区中提取字符串,然后如果我不需要复制字符串只是为了在以后查找其中的子字符串时将其删除一行会更好.
我的变量如下:
char output[100];
int index = 0;
char* substring;
Run Code Online (Sandbox Code Playgroud)
我想要一个函数,如果substring在输出[0:index]中则返回true,否则返回false.
任何帮助或领导将非常感谢!
编辑:我正在为atmelμC编写一段代码,所以看起来我只限于那些函数.
编辑2:实际上我似乎可以使用标准string.h中的所有函数
编辑3:我在我的依赖项中检查了肯定,以及我可以调用的所有函数.
extern int ffs (int __val) __ATTR_CONST__;
extern int ffsl (long __val) __ATTR_CONST__;
extern int ffsll (long long __val) __ATTR_CONST__;
extern void *memccpy(void *, const void *, int, size_t);
extern void *memchr(const void *, int, size_t) __ATTR_PURE__;
extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__;
extern void *memcpy(void *, const void *, size_t);
extern void *memmem(const void *, size_t, const …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个我创建的自定义项目向量,但我遇到了一个非常奇怪的问题.
当我创建我的类的实例时,我没有任何问题但是当我尝试添加它时,我有一个很长的错误,我不知道该怎么做.
我不知道它是否有帮助,但m_mesureList是PanneauMesure类的私有属性.
.h中的声明:
std::vector<Mesure> m_mesureList;
Run Code Online (Sandbox Code Playgroud)
使用:
void PanneauMesure::add(QPointF point1, QPointF point2, QPointF point3, QGraphicsItem *line1, QGraphicsItem *line2)
{
Mesure mesure(point1, point2, point3, line1, line2, this);
//m_mesureList.push_back(mesure);
}
Run Code Online (Sandbox Code Playgroud)
错误:
In file included from ..\testQt\/PanneauMesure.h:21,
from ..\testQt\PanneauMesure.cpp:1:
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h: In copy constructor 'Mesure::Mesure(const Mesure&)':
..\testQt\/Mesure.h:14: instantiated from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = Mesure]'
d:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_vector.h:737: instantiated from 'void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Mesure, _Alloc = std::allocator<Mesure>]'
..\testQt\PanneauMesure.cpp:104: instantiated from here
d:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtGui/qwidget.h:806: error: 'QWidget::QWidget(const QWidget&)' is private
..\testQt\/Mesure.h:14: error: within …Run Code Online (Sandbox Code Playgroud) 我正在迁移cv到cv2,我很难找到相同的cv.CvtColor功能.
我读了cv2.cvtColor存在的文档,但我不知道如何使用第三个参数.
cv2.CV_BGR2Lab不存在.也不对cv2.CV2_BGR2Lab,当我用cv.CV_BGR2Lab我得到的是一个错误:
cv2.cvtColor(img, img, cv.CV_BGR2Lab)
TypeError: only length-1 arrays can be converted to Python scalars
一段产生问题的简单代码:
img = cv2.imread(path)
cv2.cvtColor(img, img, cv.CV_BGR2Lab)
Run Code Online (Sandbox Code Playgroud) 我正在尝试做一个简单的设计来选择颜色,我正在使用QToolButton来打开QColorDialog.我的问题是,我希望QToolButton是所选颜色,但我只是设置了背景颜色,这不是我想要的.
这是一张图片:

我的代码:
QColor color = QColorDialog::getColor(m_couleur);
if (color.isValid()) m_couleur=color;
m_labelCouleur->setPalette(QPalette(m_couleur));
m_labelCouleur->setAutoFillBackground(true);
m_buttonCouleur->setPalette(QPalette(m_couleur));
m_buttonCouleur->setAutoFillBackground(true);
Run Code Online (Sandbox Code Playgroud)
基本上我希望QToolButton看起来像这样:

编辑:任何人都可以向我解释为什么网站不会让我在开头添加"大家好"?
更新:此行似乎生成错误:*line = color;
我收到以下错误,但我不明白它可以来自哪里:
错误:
HEAP [testQt.exe]:0B444FE8处的堆块修改为0B44C6B0,请求大小为76c0
生成它的行:
return QPixmap::fromImage(qimage);
Run Code Online (Sandbox Code Playgroud)
从:
QPixmap Interpolation::getData() {
QPointF pt(0, 0);
QRgb color;
QImage qimage(m_width, m_height, QImage::Format_ARGB32);
qimage.fill(Qt::transparent);
for (int i(0); i < m_height; ++i) {
m_progress->setValue(m_width+i);
QRgb *line = (QRgb *)qimage.scanLine(i);
for (int j(0); j < m_width; ++j) {
pt.setX(j);
pt.setY(i);
line += 1;
if (isInHull(pt)) {
color = colorScale(interp(&pt));
*line = color; //If I remove this part the program won't crash
}
}
}
return QPixmap::fromImage(qimage);
}
Run Code Online (Sandbox Code Playgroud)
如果它有帮助:
QRgb Interpolation::colorScale(qreal value) …Run Code Online (Sandbox Code Playgroud) 我有一个我打开使用的图像,我LoadImageM使用Get2Dput 获取像素数据我似乎无法找到任何内置函数来更改像素值.我已经使用来自多个东西试图Rectangle到CV_RGB,但没有成功的结果.