我只想知道我们在QML中是否有像QML中的私有属性那样的概念访问说明符.
如果不是,如果我想知道我的QML组件中有大约10个属性,但我必须限制只有2个属性的访问权限.我们怎样才能实现这种情况.
我们需要开发一个QtQuick项目,我们有大约100个屏幕.
我曾尝试为导航制作一个演示项目,按钮点击时有三个屏幕.我在页面之间的导航中使用了"States"的概念.最初我尝试使用'Loader',但加载器无法保留以前的页面状态,它在导航过程中重新加载整个页面.
下面是main.qml的代码片段
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
Rectangle {
id:main_rectangle
width: 360
height: 640
Page1{
id:page1
}
Page2{
id:page2
}
Page3{
id:page3
}
states: [
State {
name: "page2"
PropertyChanges { target: page3; visible:false; }
PropertyChanges { target: page1; visible:false; }
PropertyChanges { target: page2; visible:true; }
},
State {
name: "page1"
PropertyChanges { target: page3; visible:false; }
PropertyChanges { target: page2; visible:false; }
PropertyChanges { target: page1; …Run Code Online (Sandbox Code Playgroud) 我正在尝试将QListQML中的整数传递给C++代码,但不知怎的,我的方法无效.使用以下方法我得到以下错误:
left of '->setParentItem' must point to class/struct/union/generic type
type is 'int *'
Run Code Online (Sandbox Code Playgroud)
任何麻烦拍摄问题的输入都非常感谢
以下是我的代码段
头文件
Q_PROPERTY(QDeclarativeListProperty<int> enableKey READ enableKey)
QDeclarativeListProperty<int> enableKey(); //function declaration
QList<int> m_enableKeys;
Run Code Online (Sandbox Code Playgroud)
cpp文件
QDeclarativeListProperty<int> KeyboardContainer::enableKey()
{
return QDeclarativeListProperty<int>(this, 0, &KeyboardContainer::append_list);
}
void KeyboardContainer::append_list(QDeclarativeListProperty<int> *list, int *key)
{
int *ptrKey = qobject_cast<int *>(list->object);
if (ptrKey) {
key->setParentItem(ptrKey);
ptrKey->m_enableKeys.append(key);
}
}
Run Code Online (Sandbox Code Playgroud) 我执行它时,我对下面代码的输出感到困惑.
码:
int add(int a, int b)
{
cout<<"inside int add function"<<endl;
return a+b;
}
float add(float a, float b)
{
cout<<"inside float add function"<<endl;
return a+b;
}
int main()
{
cout<<add(10.0f,20.0f)<<endl<<add(20,50);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
inside int add function
inside float add function
30
70
Run Code Online (Sandbox Code Playgroud)
我不明白cout消息的顺序是在控制台中打印出来的.但我预计上面的程序输出如下
inside float add function
30
inside int add function
70
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下上述行为.
我只是在想,当我们使用会发生什么free()用newC++编写.
如果我们使用free(),new那么可以释放内存.它只是析构函数不会被调用.离开行为就像悬挂指针一样.
我明白上面我们不应该使用它free(),new因为它可能会破坏堆.
但是,我还希望在概念上可视化行为.
我有一个要求,我有 QAbstractListModel ,它正在不断更新。QAbstractListModel的数据类型是整数类型。
我想以特定的时间间隔将整个数据复制到向量中,以便向量不断更新,我可以进一步使用它。
知道如何通过索引迭代 QAbstractListModel 并将其复制到向量中。
这是在一次采访中向我提出的问题.
如果Vtable是在编译时创建的,并且vptr在运行时被分配给对象,那么如果我们的类中有虚拟构造函数,那么为什么编译器会给出编译时错误?
我解释了整个机制.但是他对' 为什么编译时错误而不是运行时错误 ' 更感兴趣
我告诉他,C++指南是用来编写的,因此编译器会在编译时发送错误.
能否请你告诉我同样的原因
我知道这是非常基本的,但不知何故我正在研究不同的技术,我已经把我的C++概念搞得一团糟
我创建了一个简单的程序,但是在调用析构函数时它会给出异常.
以下是代码:
#include "stdafx.h"
#include<iostream>
using namespace std;
class Employee
{
public:
Employee(char *name){
cout<<"Employee::ctor\n";
myName_p = new char(sizeof(strlen(name)));
myName_p = name;
}
void disp(){cout<<myName_p;}
~Employee()
{
cout<<"Employee:dtor\n\n";
delete myName_p;
}
private:
char *myName_p;
};
int main()
{
Employee emp("check");
emp.disp();
return(0);
}
Run Code Online (Sandbox Code Playgroud)
要求所有人明确这个基本概念.根据我的理解,我们不能使用delete [],因为在这种情况下我们没有使用new [].虽然我尝试过使用delete [],但它仍然给出了错误
c++ ×7
qml ×4
qt ×4
qt-quick ×4
constructor ×1
destructor ×1
exception ×1
free ×1
new-operator ×1
vtable ×1