我想在qstringlist中获取每个元素并从列表中获取原始数据,而不是pyqt存储它的原始数据.
def find(self):
self.foundFileList.setRowCount(0)
fileName = self.inputFileName.currentText()
path = self.directoryPath.currentText()
maxSize = Decimal(self.maxFileSize.value())
i = 0
self.updateComboBox(self.inputFileName)
self.updateComboBox(self.directoryPath)
self.currentDir = QtCore.QDir(path)
if not fileName:
fileName = "*"
allFiles = self.currentDir.entryList([fileName],
QtCore.QDir.Files | QtCore.QDir.NoSymLinks, QtCore.QDir.Size)
files = self.currentDir.entryList([fileName],
QtCore.QDir.Files | QtCore.QDir.NoSymLinks, QtCore.QDir.Size)
for fn in allFiles:
file = QtCore.QFile(self.currentDir.absoluteFilePath(fn))
size = Decimal((QtCore.QFileInfo(file).size() + 1023) / 1024)
if size > maxSize:
files.removeAt(i)
i += 1
self.showFiles(files)
def showFiles(self, files):
##Clean house before new round of files is displayed
del nameList[0:len(nameList)]
del fileList[0:len(fileList)] …Run Code Online (Sandbox Code Playgroud) 如何在QComboBox中找到QString?我想得到组合框中与我的字符串对应的元素的索引.有原生方法吗?
提前致谢.
我有一个公共职能:
void determineAction(QStringList tempL); // in header file
void CompArch::determineAction(QStringList tempL)
{
}
//in cpp file
Run Code Online (Sandbox Code Playgroud)
我收到错误:
CompArch.cpp:127:6: error: ‘tempL’ has incomplete type
/usr/include/qt4/QtCore/qstring.h:77:7: error: forward declaration of ‘struct QStringList’
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样.
我试图在qml-javascript中动态创建对象.创建对象的函数是:
function createSpriteObjects(xPos,yPos,cnt,imgsrc,jsonObject) {
var title;
title = jsonObject.matches[cnt].recipeName;
var component = Qt.createComponent("FlickItem.qml");
component.createObject(wall.contentItem, {"color":"white", "x":xPos,"y":yPos,"src":imgsrc,"opacity":1,"title":title});
}
Run Code Online (Sandbox Code Playgroud)
接收文件(FlickItem.qml)具有属性字符串标题,稍后将其分配给Text项的文本字段:
import QtQuick 2.0
Rectangle {
id: name
opacity: 0
property string title: ""
width:100
height:100
color:"white"
property string src: ""
Image {
id:recipeimages
source: src
width:240
height:160
}
Text {
id: title
anchors.bottom: recipeimages.bottom
anchors.horizontalCenter: recipeimages.horizontalCenter
anchors.bottomMargin: 5
color: "white"
font.pixelSize: 24
text:title
}
Run Code Online (Sandbox Code Playgroud)
返回以下错误:
无法将QQuickText分配给QString
有什么方法吗?
如何将QString转换为十进制?
在C#代码中,它看起来像这样:
public static decimal ConvertToDecimal(string tekst, bool upperOnly)
{
decimal num = 0m;
decimal num2 = 1m;
string text = upperOnly ? "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234";
int i = tekst.Length - 1;
while (i >= 0)
{
num += text.IndexOf(tekst[i]) * num2;
i--;
num2 *= text.Length;
}
return num;
}
Run Code Online (Sandbox Code Playgroud) 我这里有一个非常基本的问题.我尝试了谷歌搜索一段时间,因为有很多类似的问题,但没有一个解决方案适合我.
这是一个显示问题的代码段:
QString test = "hello";
unsigned char* test1 = (unsigned char*) test.data();
unsigned char test2[10];
memcpy(test2,test1,test.size());
std::cout<<test2;
Run Code Online (Sandbox Code Playgroud)
我尝试将QString放入unsigned char数组中,但我得到的输出总是只是'h'.
谁能告诉我这里出了什么问题?
我是Qt的新手 - 但这可能是一个非常基本的c ++问题.我有一个返回QString的简单函数:
QString testclass::myfunc(int i)
{
QString result;
switch (i) {
case 1: result = "one"; break;
case 2: result = "two"; break;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这样安全吗?c编译器是否确保返回值在内存中保留足够长的时间以供调用函数使用?(或者这会冒内存损坏的风险).如果是后者,返回QString的正确方法是什么?(结果var必须是静态的吗?结果必须是testclass的成员吗?)
QString包含常量是否重要?(id case 3分配给随机字符串的结果)
如果myfunc是一个静态方法,我想从不同的线程调用怎么办?我是否必须通过引用传入额外的Qstring以确保每个调用者获得自己的变量(并返回void)?
这是实际的功能(清理了一下) - 并注意到这个功能是STATIC,以防有所不同:
QString L::toString(const L::editions &level)
{
QString levelStr;
switch (level) {
case L::one:
levelStr = "one";
break;
case L::two:
levelStr = "two";
break;
case L::three:
levelStr = "thre";
break;
default:
levelStr = "Internal Error";
break;
}
return levelStr;
}
Run Code Online (Sandbox Code Playgroud)
然而valgrind抱怨(第121行是'levelStr ="one";')
34 bytes in …Run Code Online (Sandbox Code Playgroud) 我试图在QGIS Python控制台中使用QString.
from PyQt4.QtCore import QString
Run Code Online (Sandbox Code Playgroud)
但它说:
ImportError: cannot import name QString
Run Code Online (Sandbox Code Playgroud)
在我的Python IDLE中它工作正常,但我知道QGIS带来了自己的PyQt4.这可能是什么问题?我能解决吗?
import PyQt4.QtCore
PyQt4.QtCore.QString()
Run Code Online (Sandbox Code Playgroud)
和
from PyQt4 import QtCore
QtCore.QString()
Run Code Online (Sandbox Code Playgroud)
无论如何都不行.
我正在考虑将QtCore4.dll从我自己的PyQt4安装复制到QGIS,但QGIS使用QtCore.prl和QtCore4.lib而不是QtCore.pyd和QtCore4.dll,就像我的PyQt4安装一样
当我在QGIS控制台中调用帮助(PyQt4.QtCore)时,它没有说明QString类,而Python IDLE中的操作也是如此......这真的令人沮丧......
如果有人知道该做什么会很棒:)
比较QString和char*最有效的方法是什么?
if( mystring == mycharstar ) {} 将执行malloc,
和
if(strcmp(mystring.toLocal8Bit().constData(),mycharstar ) == 0) {}
会分配一个 QByteArray
我想不会发生任何分配,你们会推荐吗?
关于什么
if(mystring == QLatin1String(mycharstar))
会更好吗?
我有一个QStringList,我需要清理一些无意义的元素:空字符串和空字符串.
我找不到QStringList快捷功能.
清除空/空字符串的最简单方法是什么?