小编Nul*_*lik的帖子

如何在SSD磁盘上TRIM块?

在C程序中,如何告诉linux内核TRIM SSD磁盘上的块?我想我必须open()使用设备和fcntl()它的东西,但是什么?它需要是通用的(即使用不同的SSD磁盘)

注意:设备上没有ext4文件系统,只是原始数据.

c linux

5
推荐指数
1
解决办法
809
查看次数

在不能接受集合的上下文中调用的集合值函数

我收到错误:

在不能接受集合的上下文中调用的集合值函数

RETURN QUERY EXECUTE在行执行此函数时:

PLSQL $ cat lookup_email.pl 
CREATE OR REPLACE FUNCTION app.lookup_email(ident_id bigint,sess bigint,company_id bigint,email varchar)
RETURNS SETOF RECORD as $$
DECLARE
    rec RECORD;
    comp_id bigint;
    server_session bigint;
    schema_name varchar;
    query varchar;
BEGIN
    schema_name:='comp' || company_id;
    select app.session.session into server_session from app.session where app.session.identity_id=ident_id and app.session.session=sess;
    IF FOUND
    THEN
        BEGIN
            query:='SELECT i.email,u.user_id FROM app.identity as i,' || schema_name || '.uzer as u WHERE i.email like ''%' || email || '%'' and i.identity_id=u.identity_id';
            RAISE NOTICE 'executing: %',query;
            RETURN …
Run Code Online (Sandbox Code Playgroud)

postgresql plpgsql set-returning-functions

5
推荐指数
1
解决办法
2万
查看次数

Qt:从C++到QML引擎抛出异常

当调用从函数中Q_INVOKABLE写入的方法时,如何抛出异常?该方法由类型的对象拥有,通过调用注册C++JavaScriptQML< MyApp >qmlRegisterType()

例如,我有以下QML代码:

TextField {
    id: fld_recipient

    onEditingFinished: {
        try {
            var identity=myapp.identities.current_Identity;
            var company=identity.companies.current_Company;
            myapp.lookup_email(identity.identity_id,company.company_id,fld_recipient.text)
        } catch(e) {
            console.log(e);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里,方法MyApp :: lookup_email()进入服务器并搜索匹配的电子邮件地址.这个过程可以通过大量错误来停止,我希望catch()语句显示该错误.

这是如何在C++方面完成的?有点像这样:

void MyApp::lookup_email(int identity_id,int company_id,QString email) {

    ....

    error_code=server->lookup_email(identity_id,company_id,email);

    if (error_code) { /// throw an exception to QML engine, 
         ????? <= what goes here ?
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ qt qml qt5

5
推荐指数
1
解决办法
816
查看次数

在Go中使用带有空结构的类型有什么用?

为什么要创建一个空结构的类型?

type FrontierSigner struct{}
Run Code Online (Sandbox Code Playgroud)

到底有什么好处呢?

go

5
推荐指数
2
解决办法
2189
查看次数

在这种情况下,括号是什么意思?

在一些源代码中我发现了这个:

if etherbase != (common.Address{}) {
    return etherbase, nil
}
Run Code Online (Sandbox Code Playgroud)

etherbase是类型common.Address,它被定义为:

// Lengths of hashes and addresses in bytes.
const (
    HashLength    = 32
    AddressLength = 20
)
// Address represents the 20 byte address of an Ethereum account.
type Address [AddressLength]byte
Run Code Online (Sandbox Code Playgroud)

问题是:在这种情况下,parethesis意味着什么?为什么不能省略它们?像这样:

if etherbase != common.Address{} {
    return etherbase, nil
}
Run Code Online (Sandbox Code Playgroud)

go

5
推荐指数
1
解决办法
91
查看次数

未找到 QML 模块

我将一个项目复制到另一个目录(分叉它),现在我总是得到QML module not found (QtQuick.Controls).,和类似的。

原始项目没有显示任何错误。我清理并重建了所有东西,但这并没有解决它。该项目编译并完美运行,所以QtCreator不知何故被愚弄,认为存在一些问题。

这可能是什么原因?我正在使用 Qt 5.11、QtCreator 4.7.1

见附图

在此处输入图片说明

项目文件:

QT += quick network
QT += quickcontrols2
QT += widgets
CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as 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 += …
Run Code Online (Sandbox Code Playgroud)

qt qt-creator qml

5
推荐指数
1
解决办法
2745
查看次数

为什么我不能在线程之间发送 Mutex&lt;*mut c_void&gt;?

我需要在 Rust 线​​程之间共享从 C++ 创建的对象。我已经将它包装在一个Mutex结构中,所以现在在线程之间发送是安全的。但是编译器不会让我做什么。

error[E0277]: `*mut std::ffi::c_void` cannot be sent between threads safely
   --> sendsync.rs:14:2
    |
14  |     thread::spawn(move || {
    |     ^^^^^^^^^^^^^ `*mut std::ffi::c_void` cannot be sent between threads safely
    |
    = help: within `Api`, the trait `std::marker::Send` is not implemented for `*mut std::ffi::c_void`
    = note: required because it appears within the type `OpaqWrapper`
    = note: required because it appears within the type `Api`
    = note: required because of the requirements on the impl of `std::marker::Send` …
Run Code Online (Sandbox Code Playgroud)

rust

5
推荐指数
1
解决办法
2022
查看次数

如何在用UTF8编码的C中打印unicode字符?

我正在尝试打印放大镜(http://www.fileformat.info/info/unicode/char/1f50e/index.htm),但出现此错误:

[niko@dev1 ncurses]$ gcc -o utf8 -std=c99 $(ncursesw5-config --cflags --libs) utf8.c 
utf8.c: In function ‘main’:
utf8.c:12:10: error: \ud83d is not a valid universal character
   printw("\ud83ddd0e\n");         // escaped Unicode 
          ^
[niko@dev1 ncurses]$ cat utf8.c
#include <locale.h>
#include <curses.h>
#include <stdlib.h>


int main (int argc, char *argv[])
{
  setlocale(LC_ALL, "");

  initscr();

  printw("\ud83ddd0e\n");         // escaped Unicode 

  getch();
  endwin();

  return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?例如,如果我有一个十进制编码,那么放大镜的编码是55357,如何在printf中将其打印到ncurses屏幕?(不使用wchar_t,因为它浪费很多内存)

c unicode ncurses utf-8

4
推荐指数
1
解决办法
919
查看次数

将 SETOF 转换为字符串

该函数json_object_keys(json)返回一个setof text. 如何将其转换setof text为所有元素均以 分隔的字符串','?我必须使用该函数array_to_string(),但它接受一个数组,而不是一个setof. 那么如何将 a 转换setof为数组。例如:

DECLARE 
    custom_fields   json;
BEGIN
    custom_fields:='{"name":"John Smith","age":23}';
    keys:=array_to_string(json_object_keys(custom_fields),','::text);
END
Run Code Online (Sandbox Code Playgroud)

上面的方法不起作用,我得到:

ERROR:  function array_to_string(text, text) does not exist
Run Code Online (Sandbox Code Playgroud)

那么,如何将 a 转换SETOF为 an ARRAY

postgresql plpgsql

4
推荐指数
1
解决办法
1864
查看次数

使用空值创建地图

我只需要使用mapfor键,我不需要存储值.所以我宣布了这样的地图:

modified_accounts:=make(map[int]struct{})
Run Code Online (Sandbox Code Playgroud)

我们的想法是使用空结构,因为它不消耗存储空间.

但是,当我尝试向地图添加条目时,

modified_accounts[2332]=struct{}
Run Code Online (Sandbox Code Playgroud)

我收到了一个编译错误:

./blockchain.go:291:28: type struct {} is not an expression
Run Code Online (Sandbox Code Playgroud)

如何向地图添加空键而没有值?

go

4
推荐指数
2
解决办法
2488
查看次数

标签 统计

go ×3

c ×2

plpgsql ×2

postgresql ×2

qml ×2

qt ×2

c++ ×1

linux ×1

ncurses ×1

qt-creator ×1

qt5 ×1

rust ×1

set-returning-functions ×1

unicode ×1

utf-8 ×1