我有多个Angular订阅SignalR集线器连接的组件。我已将SignalR集线器连接对象包装到一个角度服务中hubconnection.service.ts:
import { Injectable } from '@angular/core';
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
@Injectable()
export class HubConnectionService {
public MyHubConnection: HubConnection;
constructor() {
this.MyHubConnection = new HubConnectionBuilder()
.withUrl('/sensorHub')
.build();
this.MyHubConnection
.start()
.then(() => console.log('[HubConnectionService] Connection started'))
.catch(err => console.log('[HubConnectionService] Error while starting connection: ' + err));
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个组件,我想从中订阅通过SignalR集线器接收的数据,为此我导入我的SignalR包装器,并在构造函数中调用该.on()方法。要取消订阅该事件,我调用.off()析构函数中的方法:
export class RawdataComponent implements OnInit {
constructor(private hubConnectionService: HubConnectionService) { }
ngOnDestroy() {
this.hubConnectionService.MyHubConnection.off('Broadcast'); …Run Code Online (Sandbox Code Playgroud) 我有这个函数签名:
void myFunction(int *const ptr);
Run Code Online (Sandbox Code Playgroud)
什么是点const的关键字在这个特定背景下?
即使ptr不是const变量,我也无法修改它指向的地址,因为它是按值传递的,所以如果我有另一个这样的函数:
void myAnotherFunction(int *ptr);
Run Code Online (Sandbox Code Playgroud)
在它的实现中做了这样的事情:
//...
ptr = malloc(1023);
//...
Run Code Online (Sandbox Code Playgroud)
这不会影响传递的值(当然在这个函数之外)。
所以问题是:使用myFunction()签名而不是签名myAnotherFunction()有什么意义?(除此之外,您还会收到编译时错误)。
我想什么来实现的:我想要一套定制的baud rate一些价值观tty*般UART-mapped终端。
如何:我发现迄今唯一的办法就是使用struct termios2它位于结构<asm/termios>标题(如提到这里,第一个答案)。
到目前为止,我的解决方案效果很好,但现在我需要使用一些功能:
speed_t cfgetispeed(const struct termios *);
int tcdrain(int);
int tcflow(int, int);
int tcflush(int, int);
int tcgetattr(int, struct termios *);
pid_t tcgetsid(int);
int tcsendbreak(int, int);
int tcsetattr(int, int, struct termios *);
Run Code Online (Sandbox Code Playgroud)
问题是<asm/termios.h>没有这样的功能,我需要包括<termios.h>才能使用它们。
问题:如果我同时包含头文件(<asm/termios.h>和<termios.h>),编译器会抱怨函数和结构重新声明,他是对的。
如何在不使用一些晦涩的做法的情况下解决这个问题(例如将标题之一包装在命名空间中,就像这里提到的那样)?
所以我安装了Qt addin的Visual Studio 2013(社区版),Qt5库(32位),我正在尝试创建一个独立于所有开发配置的可执行文件(它可能使用静态或共享库,我不真的很在意这一点).
操作系统:Windows 7,x64.
为此,我将Solution Confgurationvisual studio选项更改Debug为Release,并添加所有必需的库Configuration Properties -> Linker -> Input -> Additional Dependencies.应用程序现在只在我从visual IDE运行它时启动,如果我尝试从生成的.exeI got The application was unable to start correctly (0xc000007b)error 启动它.
我搜索过并发现此错误代码表明存在以下问题之一:
qt-opensource-windows-x86-msvc2013-5.5.0),我使用其他一些也是32位的.DLL).为了检查我的应用程序需要哪些依赖项,我.exe使用Dependency Walker应用程序打开了文件,这就是它向我显示的内容:
在这个列表也是Qt5Multimedia.dll和Qt5SerialPort.dll,我通过复制.DLLs与相同的文件夹中的错误摆脱.exe.
任何想法如何解决这个问题?
我想bootstrap-notify在我的 Angular 7 应用程序中使用。
为此,我安装了该bootstrap-notify软件包(并且还安装了@types/bootstrap-notify)。
在我想要使用通知的组件中,我导入了 jQuery 服务,如下所示:
import * as $ from 'jquery';
Run Code Online (Sandbox Code Playgroud)
现在按照文档中的描述notify进行调用:
$.notify({
// options
message: 'Hello World'
},{
// settings
type: 'danger'
});
Run Code Online (Sandbox Code Playgroud)
问题是我收到此错误:
ERROR in src/app/home/home.component.ts(28,7): error TS2339: Property 'notify' does not exist on type 'JQueryStatic'.
Run Code Online (Sandbox Code Playgroud)
知道如何让它发挥作用吗?我找不到任何使用此包的 Angular (5/6/7) 示例!
我有一个结构:
typedef struct {
char fname[100], lname[100];
int age, salary;
} *employer;
Run Code Online (Sandbox Code Playgroud)
而现在,我想要一个指针变量empl1,它包含足够的空间供100名员工使用:
employer empl1 = malloc(100 * sizeof(employer));
Run Code Online (Sandbox Code Playgroud)
问题是sizeof(雇主)是4 (我的机器上指针的大小).我如何获得所有雇主结构的规模?(在我的情况下是208).
有没有直接的方法来查找std::vector容器中是否存在某组值(模式)?
假设我有这个数据容器:
std::vector<int> data { 0x00, 0xff, 0x00, 0x11, 0x12, 0x13, 0x14, 0x15 };
Run Code Online (Sandbox Code Playgroud)
而这个模式使用另一个std::vector容器描述:
std::vector<int> pattern { 0x00, 0xff, 0x00 };
Run Code Online (Sandbox Code Playgroud)
我想要:
一个布尔值,表示模式的存在.
最终,模式开始的索引.
所以我有这个代码:
#include <iostream>
#include <list>
#include <string>
#include <memory>
using namespace std;
int main() {
{
shared_ptr<string> str = new string("Marius");
cout << str + " MMG";
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
通过编译它:
clang++ -Wall -g -std=c++14 test.c++ -o test
Run Code Online (Sandbox Code Playgroud)
我明白了:
test.c++:11:22: error: no viable conversion from 'string *' (aka 'basic_string<char> *') to 'shared_ptr<string>'
shared_ptr<string> str = new string("Marius");
Run Code Online (Sandbox Code Playgroud)
哪里出错了?使用GCC我得到了同样的错误.
c++ ×3
angular ×2
c ×2
asp.net ×1
bootstrap-4 ×1
broadcast ×1
c++14 ×1
dependencies ×1
deployment ×1
dll ×1
header-files ×1
linux ×1
malloc ×1
notify ×1
qt ×1
shared-ptr ×1
signalr ×1
size ×1
stdvector ×1
struct ×1
structure ×1
subscription ×1
termios ×1
vector ×1