小编Jul*_*ien的帖子

什么是在函数调用中发送QStrings的最佳方法?

我想知道在QT中将Qstring作为参数发送到函数的最有效和最实用的方法是什么,更具体地说.我想用一个参考.问题是我也想在函数本身中实例化该字符串,例如:

这是函数原型:

void myFunction(QString & theMsg);
Run Code Online (Sandbox Code Playgroud)

这是函数调用:

myFunction(tr("Hello StringWorld"));
Run Code Online (Sandbox Code Playgroud)

现在function tr()返回一个QString,但它不能用于引用(我可以看到原因).

我必须这样做:

QString theQstr("Hello StringWorld"); 
myFunction(theQstr);
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法在仍然使用引用时执行此操作,或者我可以只更改函数参数以使用QString,它仍然有效吗?

string qt pointers pass-by-reference

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

使用url var下载文件Curl

我想用Curl下载一个文件.问题是下载链接不是直接的,例如:

http://localhost/download.php?id=13456
Run Code Online (Sandbox Code Playgroud)

当我尝试使用curl下载文件时,它会下载文件download.php!

这是我的卷曲代码:

        ###
        function DownloadTorrent($a) {
                    $save_to = $this->torrentfolder; // Set torrent folder for download
                    $filename = str_replace('.torrent', '.stf', basename($a));

                    $fp = fopen ($this->torrentfolder.strtolower($filename), 'w+');//This is the file where we save the information
                    $ch = curl_init($a);//Here is the file we are downloading
                    curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // Important 
                    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
                    curl_setopt($ch, CURLOPT_URL, $fp);
                    curl_setopt($ch, CURLOPT_HEADER,0); // None header
                    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); // Binary trasfer 1
                    curl_exec($ch);
                    curl_close($ch);
                    fclose($fp); 
    }
Run Code Online (Sandbox Code Playgroud)

有没有办法在不知道路径的情况下下载文件?

php curl

7
推荐指数
1
解决办法
2370
查看次数

使用Johnny-Five和React

我想使用Johnny-Five并使用React JS创建一个接口.

我使用了这个React安装教程.我在同一个项目中安装了Johnny-Five:http://johnny-five.io/(Johnny-Five独立工作,独立应用程序.这使我可以控制我的Arduino).

我的React index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import MainRouter from './routes';
import registerServiceWorker from './registerServiceWorker';
import five from 'johnny-five';

var board = new five.Board({
  port: "/dev/ttyACM0" 
});

board.on("ready", function() {
  var led = new five.Led(13);
  led.blink(500);
});

ReactDOM.render( <MainRouter />, document.getElementById('root'))
registerServiceWorker();  
Run Code Online (Sandbox Code Playgroud)

当我运行React时,网站启动但是电路板没有反应!虽然没有React的相同代码可以很好地工作.任何让Johnny-Five与React合作的想法?

arduino node.js reactjs johnny-five

6
推荐指数
1
解决办法
767
查看次数

Kivy可替换按钮的可点击图像

寻找一种方法来使用图像而不是传统的按钮与kiv​​y.
我尝试使用background_disabled_normalbackground_disabled_down
这是我的.kv文件中的按钮部分:

Button:
    on_press: root.do_action()
    background_disabled_normal: str(False)
    Image:
        source: 'icon.png'
        y: self.parent.y + self.parent.height - 250
        x: self.parent.x
        size: 250, 250
        allow_stretch: True
Run Code Online (Sandbox Code Playgroud)

但不行

python kivy

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

在Qt5中使用sqlite

我在ubuntu上

#include <sqlite3.h>    /* sqlite3 */


void prog::on_pushButton_clicked()
{
    sqlite3 *db;
    int rc = sqlite3_open("/home/profile.sqlite", &db);
    if (rc != SQLITE_OK) {
        fprintf(stderr, "Cannot open database: %s\n",
                sqlite3_errmsg(db));
        sqlite3_close(db);    
     }
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

在此输入图像描述

c++ sqlite qt qt5

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

标签 统计

qt ×2

arduino ×1

c++ ×1

curl ×1

johnny-five ×1

kivy ×1

node.js ×1

pass-by-reference ×1

php ×1

pointers ×1

python ×1

qt5 ×1

reactjs ×1

sqlite ×1

string ×1