我正在使用Qt 5.2 beta,Qt Quick 2.1.
我有直接的Flickable组件问题.
这是最小的工作代码示例:
import QtQuick 2.1
import QtQuick.Controls 1.0
ApplicationWindow {
width: 300
height: 200
Rectangle {
anchors.fill: parent
color: "green"
Flickable {
id: flickArea
anchors {fill: parent; margins: 10; }
contentWidth: rect.width;
contentHeight: rect.height
Rectangle {
id: rect
x: 0; y: 0;
width: 200; height: 300;
color: "lightgrey"
Rectangle {
anchors { fill: parent; margins: 10; }
color: "red"
}
}
}
}
Button {
anchors.bottom: parent.bottom;
anchors.horizontalCenter: parent.horizontalCenter;
text: "Scale flickArea"
onClicked: …Run Code Online (Sandbox Code Playgroud) 我正在使用QTreeView向用户显示一些数据.我想要的是将实际对象附加到使用表示的每个节点QStandardItem.
要将对象引用保存到QStandardItem:
QStandardItem *child = new QStandardItem(s);
child->setFlags(child->flags() & ~Qt::ItemIsEditable);
child->setData(QVariant(QVariant::UserType, i), Qt::UserRole + 10);
Run Code Online (Sandbox Code Playgroud)
要在UI中单击它时访问实际对象:
void MyOtherClass::handleTreeViewSelectionChanged(const QModelIndex &i)
{
MyClass* o = i.data(Qt::UserRole + 10).value<MyClass*>();
// do other stuff with o
}
Run Code Online (Sandbox Code Playgroud)
上面的调用只是返回NULL.有谁知道如何处理这样的要求?
我在网上发现绝对没用.
任何帮助将受到高度赞赏.
我是C++和Qt的新手.
我想填充一个QTextEdit对象QTextBlocks,我该怎么做?
例如,如果我有句"鱼来了",我怎么把每个单词都放到自己的单词中QTextBlock并添加该单词QTextEdit,或者我误解了它QTextBlock是如何实际运作的?
我是symbian环境的新手,我正在尝试使用Qt Symbian构建一个应用程序,我还需要使用etel3rdparty.lib和头文件,我也包含了lib路径和包含路径,但是我收到了很多编译错误.
如下:
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32const.h:9,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32cmn.h:8,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32std.h:13,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32base.h:8,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/etel3rdparty.h:20,
from ..\AutoStart\dialog.cpp:10:
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32def.h:872: error: 'Int64' does not name a type
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32def.h:883: error: 'Uint64' does not name a type
In file included from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32cmn.h:8,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32std.h:13,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32base.h:8,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/etel3rdparty.h:20,
from ..\AutoStart\dialog.cpp:10:
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32const.h:860: error: 'TInt64' does not name a type
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32const.h:871: error: 'TInt64' does not name a type
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32const.h:882: error: 'TUint64' does not name a type
In file included from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32std.h:13,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32base.h:8,
from c:\NokiaQtSDK\Symbian\SDK\epoc32\include/etel3rdparty.h:20,
from ..\AutoStart\dialog.cpp:10:
c:\NokiaQtSDK\Symbian\SDK\epoc32\include/e32cmn.h:41: …Run Code Online (Sandbox Code Playgroud) 我有一个Qt嵌入式应用程序,我在OpenSuse 11.4中开发,我需要加载一个TTF字体文件.但是,当我调用int QFontDatabase::addApplicationFont()函数时,它正在返回-1.
在阅读文档后,我发现目前不支持在没有fontconfig的Unix/X11平台上添加应用程序字体.
我通过YaST检查我是否安装了fontconfig,并且已安装 - 但我不认为它是相关的因为我使用的是qt嵌入式库.我想我必须有fontconfig支持qt嵌入式库,但我该怎么做?
fontconfig甚至支持qt-embedded吗?谁能告诉我发生了什么事?
我是Qt及其IDE Qt Creator的新手,所以原谅我的无知.当我尝试编译我的代码时,我得到了异常
"Qt Creator需要一个编译器设置来构建.在套件选项中配置编译器".
我安装了MingGW来编译C++代码.但是,我在为Qt Creator配置它时遇到问题.
任何帮助将不胜感激.谢谢
QLabel无论内容如何,我想要扩展到容器的全宽度.(我想要这个,因为我动态设置文本并稍后添加小部件,导致它切断部分文本)
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setFixedSize(100,100);
QHBoxLayout *layout = new QHBoxLayout;
this->setLayout(layout);
QLabel *label = new QLabel;
label->setStyleSheet("background-color:blue");
label->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
label->setText(tr("test"));
layout->addWidget(label, 0, Qt::AlignTop | Qt::AlignLeft);
}Run Code Online (Sandbox Code Playgroud)
此代码显示蓝框不会扩展到整个宽度,为什么?
我在查找为我的qtcreator应用程序创建类图的工具时遇到了问题我尝试了BOUML和Umbrello,但是它们都遇到了一些类的问题.
我正在研究Ubuntu.
我正在尝试编写我的第一个Qt安装程序并遇到问题.在我的安装程序中,在其中一个软件包中,我需要.exe在安装结束时运行一个文件并添加一个环境变量.
我认为这样做的方法是使用package.xml文件中的脚本选项,但我不知道如何编写该脚本,我找不到一步一步解释如何在任何地方执行此操作.
有人可以帮忙吗?
我QtConcurrent::run用来运行一个函数,并通过引用传递值,但值的内存地址是不同的.
但是如果我通过指针传递值,地址是一样的!我无法弄清楚.我错过了什么吗?
这是代码.
void ptr(QString* s)
{
qDebug() << "pass by ptr: " << s;
}
void ref(QString& s)
{
qDebug() << "pass by ref: " << &s;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
QFuture<void> f1 = QtConcurrent::run(ptr, &str);
f1.waitForFinished();
QFuture<void> f2 = QtConcurrent::run(ref, str);
f2.waitForFinished();
qDebug() << "address of str: " << &str;
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
输出:
pass by ptr: 0x28fefc
pass by ref: 0x525de4
address of str: 0x28fefc
Run Code Online (Sandbox Code Playgroud)