我已经派生出类QTabBar实现"+"(new tab button)按钮使用QToolButton(类似于谷歌浏览器).但是,它在我的Linux机器上工作,但在我的Windows机器上不起作用.通过不工作我的意思QToolButton是在我看不到,windows machine但它在我的Linux机器(Ubuntu)中可见.我无法进一步调试,因为我已经尝试了很少的实验来理解原因,但它没有用.
我的源文件:
#include "tabbar.h"
TabBar::TabBar(QWidget *parent) : QTabBar(parent)
{
new_button_ = new QToolButton(this);
new_button_->setObjectName(QStringLiteral("AddButton"));
new_button_->setText("+");
new_button_->setFixedSize(QSize(20, 20));
connect(new_button_, SIGNAL(released()), this, SLOT(emit_new()));
movePlusButton();
}
QSize TabBar::sizeHint(void) const
{
QSize old = QTabBar::sizeHint();
return QSize(old.width() + 45, old.height());
}
void TabBar::emit_new(void)
{
emit newClicked();
}
void TabBar::movePlusButton(void)
{
quint64 totalWidth = 0;
for (long i=0; i < count(); i++)
totalWidth += tabRect(i).width();
quint64 h = …Run Code Online (Sandbox Code Playgroud) 我正在使用QN9021SoC controller mode(BLE蓝牙核心规范v4.0).它支持一些标准HCI命令以及一些供应商特定命令.我想把它贴在我的ubuntu笔记本电脑上.
我使用的命令是hciattach.
hciattach -s 9600 /dev/ttyUSBx any 9600 noflow nosleep
Run Code Online (Sandbox Code Playgroud)
hcidump执行时的节目sudo hciconfig hci1 up.
HCI sniffer - Bluetooth packet analyzer ver 5.37
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Command Complete (0x0e) plen 12
Read Local Supported Features (0x04|0x0003) ncmd 11
status 0x00
Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Complete (0x0e) plen 12
Read Local Version Information …Run Code Online (Sandbox Code Playgroud) 我已经安装openwrt在beaglebone black. 我发现它没有gcc,g++或任何其他编译器/工具链。
如何在 openwrt 中安装 C 和 C++ 编译器(最好是 g++)?
我开发了 BLE 应用程序以openwrt使用BLUEZV5.30. 我能够通过提取源代码gatttool和hcitool. 我还添加了这些工具提供的更多功能(如阅读rssi)。
但是,我已将bluez堆栈升级为,5.42并且计划将DBUS接口用于所有与 BLE 相关的操作。我想要的功能:
我能够使用我用 C++ 编写的代码执行上述所有操作(绑定和配对除外)。但是,由于我现有代码的一些问题以及无法配对/绑定,我想迁移到 dbus 接口。但是,我不确定BLUEZ DBUS APIAPI 提供的错误和功能。我已经阅读了这个API 文档,但它没有给出任何关于 DBUS 接口的清晰图片。
我的问题是我不确定我是否可以获得所有必需的功能dbus api?我已经阅读了文档(bluez dbus api),但我仍然不确定。
我在堆栈溢出上搜索以找到与我的问题相关的答案。但我没有找到任何答案。
我有一个启动线程的主线程(我的 main() 函数)。新线程运行 GMainLoop。g_io_watch在我的主函数中,我不断通过调用一些文件描述符来添加源。但如果事件被调度,我会得到垃圾数据。
下面是我正在尝试的代码的一小部分:
GMainLoop *loop;
gpointer event_loop_thread(gpointer arg)
{
g_main_loop_run(loop);
g_main_loop_unref(loop);
return NULL;
}
int init()
{
loop = g_main_loop_new(NULL, FALSE);
g_thread_new(NULL, event_loop_thread, NULL);
return 0;
}
gboolean __hci_service(GIOChannel *source, GIOCondition condition, gpointer data)
{
// Doing something
return FALSE;
}
int main()
{
init();
int _adapter_id = hci_devid("hci0");
int hci_dev = hci_open_dev(_adapter_id);
GIOChannel *p_hci_io = g_io_channel_unix_new(dev_id);
GIOCondition cond = (GIOCondition)(G_IO_IN);
g_io_add_watch(p_hci_io, cond, __hci_service, NULL);
while (true);
// I will close file descriptor
return 0; …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个sidebar类似于in Qt Creator(左边一个)的类.我现在不知道让它看起来像Qt创作者那样,因为我看起来很难看!
侧边栏:
#ifndef _SIDEBAR_H_
#define _SIDEBAR_H_
#include <QVector>
#include <QString>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QPixmap>
#include <iostream>
class SideBar : public QWidget
{
public:
SideBar(QWidget *parent=nullptr);
void addIcon(const char *name);
void addIcon(QString &name);
private:
QVBoxLayout *_layout;
};
#endif // SIDEBAR_H
Run Code Online (Sandbox Code Playgroud)
sidebar.cpp
#include "sidebar.h"
#include <QPushButton>
#include <QIcon>
SideBar::SideBar(QWidget *parent) : QWidget(parent)
{
_layout = new QVBoxLayout(this);
setLayout(_layout);
}
void SideBar::addIcon(const char *name)
{
QString str(name);
addIcon(str);
}
void SideBar::addIcon(QString &file) …Run Code Online (Sandbox Code Playgroud) 我试图将一个对象绑定到一个函数,但正在调用基类的类函数。代码只是真实代码的一个例子。我只会在后面的实际代码中使用字符串。
class A {
public:
virtual void f(const std::string &s) {
std::cout << "A " << s << std::endl;
}
};
class B : public A {
public:
void f(const std::string &s) override {
std::cout << "B " << s << std::endl;
}
};
void main() {
std::unique_ptr<A> a = std::make_unique<B>();
std::function<void(const std::string &)> callback
= std::bind(&A::f, *a, std::placeholders::_1);
callback("my string");
}
Run Code Online (Sandbox Code Playgroud)
结果是
A my string
Run Code Online (Sandbox Code Playgroud)
我试图将其更改为 &B:f,但出现错误。
No viable conversion from 'typename _Bind_helper<__is_socketlike<void (B::*)(const basic_string<char> &)>::value, void (B::*)(const basic_string<char> …Run Code Online (Sandbox Code Playgroud) 我有一个在 C++ 编程语言中使用 OpenSSL 的 SSL/TLS 客户端程序。我正在寻找验证函数调用X509返回的服务器证书 ( ) 的SSL_get_peer_certificate方法。另外,我使用SSL_CTX_load_verify_locations函数加载了自己的 CA 证书。CA 认证了服务器证书。
我能够与我的服务器建立 SSL 会话。现在,我想使用我自己的 CA 验证在 SSL 握手期间收到的服务器证书。我找不到在 C 或 C++ 中做到这一点的方法。
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/x509_vfy.h>
#define DEFAULT_PORT_NUMBER 443
int create_socket(char *, uint16_t port_num);
int openSSL_client_init()
{
OpenSSL_add_all_algorithms();
ERR_load_BIO_strings();
ERR_load_crypto_strings();
SSL_load_error_strings();
if (SSL_library_init() < 0)
return -1;
return …Run Code Online (Sandbox Code Playgroud) 我想通过遍历一个for循环来填充数组。
假设我有:
int8 myArray[30] = {0}; // Declaring and initializing an array which contains maximum 30 elements
Run Code Online (Sandbox Code Playgroud)
在for循环中向数组添加元素:
for (i = 0; i<5; i++)
{
myArray[0+(i*5)] = getNumberfromFunction1();
myArray[1+(i*5)] = getNumberfromFunction2();
myArray[2+(i*5)] = getNumberfromFunction3();
myArray[3+(i*5)] = getNumberfromFunction4();
myArray[4+(i*5)] = getNumberfromFunction5();
myArray[5+(i*5)] = getNumberfromFunction6();
}
Run Code Online (Sandbox Code Playgroud)
循环的每个元素应按以下方式填充:
myArray [0] = getNumberfromFunction1();
myArray [1] = getNumberFromFunction2();
...
...
myArray [5] = getNumberFromFunction6();
myArray [6] = getNumberFromFunction1();
....
....
i = 0的第一圈,索引正确:
myArray[0] = ..
myArray[1] = ..
..
..
myArray[5] = ..
Run Code Online (Sandbox Code Playgroud)
当i …
给定的答案是O(nlog(n)),但我也在Wikipedia上查找它,并说它是log(n)。
哪一个是正确的?
另外,搜索不平衡二叉树的最坏情况复杂度是什么?
我刚刚开始学习 python,我知道我要问的是非常基本的,但无论如何我都会得到它,
# adding an If statements grabbing the even numbers
evenNumber = [num for num in range(0,11) if num%2==0]
evenNumber
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用 for 循环以有组织的方式来完成它,但我错过了一些东西:
#adding an If statements grabbing the even numbers using for loop
evenNumber = []
for num in range(0,11):
evenNumber.append(num if num%2==0)
evenNumber
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助,请不要介意我的简单问题:)