小编Vin*_*ira的帖子

在不同模块中的指令和控制器之间共享数据

我已经和AngularJS玩了几天,想出了一些我还无法解决的问题.

每个联系人都可以有多个地址和电话号码.由于插入和编辑联系人在UI级别需要几乎相同的功能,因此我决定创建一个类似以下的指令来处理地址和电话:

地址:

(function () {
    var app = angular.module("AddressesEditorModule", []);
    app.directive("addressesEditor", function () {
        return {
            restrict: "E",
            templateUrl: "/addressesEditorTemplate.html",
            controller: function ($scope) {
                this.addresses = [
                    // this will hold addresses.
                ];

                // ...
            }
        }
})();
Run Code Online (Sandbox Code Playgroud)

电话:

(function () {
    var app = angular.module("PhonesEditorModule", []);
    app.directive("phonesEditor", function () {
        return {
            restrict: "E",
            templateUrl: "/phonesEditorTemplate.html",
            controller: function ($scope) {
                this.phones = [
                    // this will hold phones.
                ];

                // ...
            }
        }
})();
Run Code Online (Sandbox Code Playgroud)

我省略了在指令中声明的方法来处理addressesphones …

angularjs

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

触发属性更改的QML动画

我正在使用一些CPU密集型代码实现一个应用程序.此代码必须更新QML中设计的界面以显示其结果.

界面由网格和几个块组成,其中包含一些内容.在Grid完全C++实现的,而且Block是唯一的QML.

Block.qml

import QtQuick 2.3

Item {
    id: root

    // lot of non-related stuff here.

    Behavior on x {
        NumberAnimation {
            duration: 1000
            easing.type: Easing.Linear

            onRunningChanged: {
                console.log("behavior on x");
            }
        }
    }

    Behavior on y {
        NumberAnimation {
            duration: 1000
            easing.type: Easing.Linear

            onRunningChanged: {
                console.log("behavior on y");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

每个块都是用C++创建的,并相应地定位.

问题是,有时我必须移动块,我想触发一个动画.为了实现这一点,我已经包含了Behavior您可能已经注意到的元素.

但是当我从C++代码更改块的位置时,不会触发该行为.在Block简单地改变其位置,没有任何动画.

我用来改变块位置的代码是:

void Grid::setBlockPosition(QQuickItem *block, unsigned i, unsigned j)
{
    float x, y;
    x = GRID_MARGIN_LEFT + …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml

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

C++中的多线程抛出线程构造函数失败:资源暂时不可用

编辑:

我正在以矩阵乘法为例学习多线程,我创建了这个程序:

#include <iostream>
#include <vector>
#include <thread>
#include <functional>

using namespace std;

int N = 50;
void do_multiply_for_row(const vector<vector<int> >& matrix, int i, int N, vector<int>& answer) {
    for (int j = 0; j < N; j++) {
        answer[j] = 0;
        for (int k = 0; k < N; k++) {
            answer[j] += matrix[i][k] * matrix[k][j];
        }
    }
    cout << "Done " << i <<  endl;
}

int main() {
    vector<vector<int> > matrix(N, vector<int> (N, 0));
    int x = …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading c++11

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

标签 统计

c++ ×2

angularjs ×1

c++11 ×1

multithreading ×1

qml ×1

qt ×1