qtcore

Substitute for sleep function in Qt/C++

廉价感情. 提交于 2019-12-02 15:39:35
问题 So I am writing a program that displays each letter of a word for 1 second with a 1 second interval between the letters. (It's for a spelling exercise for grade 1). I am currently using the sleep function to "pause" the program for 1 second before it "updates" again. After that it displays the word for a second and then removes it. I repaint before the sleep function, else it does not seem to update in time. Here is the basic function: QString word = "apple"; QThread thread; for(int i = 0; i

How to detect when ssh connection (over a QProcess) has finished?

大城市里の小女人 提交于 2019-12-02 05:38:55
I am running an ssh tunnel from an application using a QProcess : QProcess* process = new QProcess(); process->start("ssh", QStringList()<<"-L"<<"27017:localhost:27017"<<"example.com"); So far it works great, the only problem being that there is no way for me to see when the port has actually been created. When I run the command on a shell, it takes about 10 seconds to connect to the remote host after which the forwarded port is ready for usage. How do I detect it from my application? EDIT: As suggested by vahancho, I used the fact that post-connection there is some output on the terminal that

QML data folder

怎甘沉沦 提交于 2019-12-02 03:33:05
问题 Im my app based on QML I use Camera and CameraCapture to capture an image from the camera. After it was captured I want to store captured image in application data folder with CameraCapture.captureToLocation() . But I have no idea how to get path to this folder. So my question - how can I get path to application folder wit write permissions? Is there way in Qt to get it? It should be system specified folder, I guess. For example in Android it should be /data/data/AppName. As I see

QML data folder

六月ゝ 毕业季﹏ 提交于 2019-12-02 03:12:28
Im my app based on QML I use Camera and CameraCapture to capture an image from the camera. After it was captured I want to store captured image in application data folder with CameraCapture.captureToLocation() . But I have no idea how to get path to this folder. So my question - how can I get path to application folder wit write permissions? Is there way in Qt to get it? It should be system specified folder, I guess. For example in Android it should be /data/data/AppName. As I see LocalStorage creates its files in some similar place. /data/data/AppName is not mapped in QStandardPaths , but I

os.walk analogue in PyQt

﹥>﹥吖頭↗ 提交于 2019-12-02 01:09:23
问题 Before I can continue to implement recursive dir/file search with some filtering for some tasks I want to know if Qt/PyQt has analogue of os.walk . Main app is a GUI app in PyQt4 and all text fields in a QString s and path objects (files, directories) uses QFile , QDir , QFileinfo for manipulations. As analogue I mean fast and convenient recursive fs-tree traversal tool. Should I use os.walk or something much faster and more informative? PS. Maybe this can help me but I'm not sure if this

os.walk analogue in PyQt

戏子无情 提交于 2019-12-01 22:36:48
Before I can continue to implement recursive dir/file search with some filtering for some tasks I want to know if Qt/PyQt has analogue of os.walk . Main app is a GUI app in PyQt4 and all text fields in a QString s and path objects (files, directories) uses QFile , QDir , QFileinfo for manipulations. As analogue I mean fast and convenient recursive fs-tree traversal tool. Should I use os.walk or something much faster and more informative? PS. Maybe this can help me but I'm not sure if this more efficient than os.walk . Should I use os.walk or something much faster and more informative? There is

Qt/C++ Convert QString to Decimal

限于喜欢 提交于 2019-12-01 21:34:33
How Can I convert QString to decimal ? In C# code it look like that: 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; } lpapp As per documentation : int QString::toInt(bool * ok = 0, int base = 10) const Returns the string converted to an int using base base , which is 10 by default and must

QString replace only first occurrence

耗尽温柔 提交于 2019-12-01 17:28:24
Is there simple way of replacing only first occurrence of some substring by other substring in QString? It can be at any position. You could try this: QString str("this is a string"); // The initial string. QString subStr("is"); // String to replace. QString newStr("at"); // Replacement string. str.replace(str.indexOf(subStr), subStr.size(), newStr); Resulting string will be: that is a string There is no convenience method for the operation you wish to have. However, you can use the following two methods to build your custom operation: int QString::indexOf(const QString & str, int from = 0, Qt

QString replace only first occurrence

前提是你 提交于 2019-12-01 17:25:53
问题 Is there simple way of replacing only first occurrence of some substring by other substring in QString? It can be at any position. 回答1: You could try this: QString str("this is a string"); // The initial string. QString subStr("is"); // String to replace. QString newStr("at"); // Replacement string. str.replace(str.indexOf(subStr), subStr.size(), newStr); Resulting string will be: that is a string 回答2: There is no convenience method for the operation you wish to have. However, you can use the

Understanding QTimer with Lambda and recursive function call

萝らか妹 提交于 2019-12-01 17:22:51
I have the following code: void class::Testfunc() { QTimer* timer = new QTimer; QObject::connect(timer, &QTimer::timeout, [this](){ emit Log("Time out..."); TestFunc(serverAddress, requestsFolderPath); // deleteLater(); //*** why does this crash if used to replace the connect below? }); connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater); timer->setSingleShot(true); timer->start(1000); } A single shot timer is created with a timout connected to a lambda function that logs the entrance to the lambda function each second (prints text to stdout) and calls the function again. This works