qtcore

How do you serialize a QMap?

人盡茶涼 提交于 2019-12-22 13:08:08
问题 I'm trying to learn how to serialize QMap objects in windowed applications, using this code: #include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QString> #include <QDataStream> #include <QMap> #include <QDebug> void write () { QString filename = "Z:/snippets.txt"; QFile myFile (filename); if (!myFile.open(QIODevice::WriteOnly)) { qDebug() << "Could not write " << filename; return; } QMap<QString,QString> map; map.insert("one","this is 1"); map.insert("two","this is 2

Can i read from .ini file which located in resources files?

独自空忆成欢 提交于 2019-12-22 08:52:58
问题 #include "mainwindow.h" #include "ui_mainwindow.h" #include <QSettings> #include <QDebug> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSettings * qsettings = new QSettings(":/config.ini",QSettings::IniFormat); bool status = qsettings->value("preview","").toBool(); qDebug() << status; } MainWindow::~MainWindow() { delete ui; } Once i could do it but now i don't know whats wrong. When i googled this problem i just saw that this

How to use QCommandLineParser for arguments with multiple params?

那年仲夏 提交于 2019-12-22 04:58:41
问题 I wonder, how can I use multiple- or sub-arguments with QCommandLineParser? For example: /home/my_app --my_option_with_two_params first_param second_param --my-option-with-one-param param? 回答1: Try this which has the analogy of -I /my/include/path1 -I /my/include/path2 : --my_option_with_two_params first_param --my_option_with_two_params second_param ... and then you can use this method to have access to the values: QStringList QCommandLineParser::values(const QString & optionName) const

How to find out from the slot which signal has called this slot?

偶尔善良 提交于 2019-12-21 04:32:18
问题 I mean if I have many different signals which are connected to the same slot. I saw this question but can't understand the link in the answer. Can you give me simple example? 回答1: I think you can use this method: [protected] int QObject::​senderSignalIndex() const From Qt documentation: Returns the meta-method index of the signal that called the currently executing slot , which is a member of the class returned by sender(). If called outside of a slot activated by a signal, -1 is returned.

Qt “signal undefined reference error” after inheriting from QObject

走远了吗. 提交于 2019-12-21 04:13:39
问题 I recently needed to add a signal to a class, so I changed the class to inherit from QObject and added the Q_OBJECT macro into the class definition. Since doing so I get "signal undefined reference error for 'vtable for CLICommand'" error on the class line below: // File clicommand.h #include <QString> #include <QStringList> #include <QTcpSocket> #include "telnetthread.h" class CLICommand : public QObject { Q_OBJECT public: CLICommand(TelnetThread *parentTelnetThread); signals: void signal

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

放肆的年华 提交于 2019-12-20 04:04:15
问题 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:

Qt/C++ Convert QString to Decimal

ε祈祈猫儿з 提交于 2019-12-20 02:29:29
问题 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; } 回答1: As per documentation: int QString::toInt(bool * ok = 0, int base

Understanding QTimer with Lambda and recursive function call

戏子无情 提交于 2019-12-19 18:20:33
问题 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

How to setup QSerialPort on a separate thread?

我们两清 提交于 2019-12-18 13:34:18
问题 Following the official documentation I'm trying to do this: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QThread *thread = new QThread; Worker *worker= new Worker(); worker->moveToThread(thread); //init connections thread->start(); } Worker constructor: Worker::Worker(QObject *parent) : QObject(parent) { serial = new QSerialPort(this); //passing the parent, which should be the current thread } No compiling errors but when I execute it throws me this: QObject: Cannot create

How to Compress Slot Calls When Using Queued Connection in Qt?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 10:42:47
问题 After reading some articles like this about Qt Signal-Slot communications I still have a question concerning the queued connection. If I have some threads sending signals all the time to each other and lets say one thread_slow is running a slow method in it's event loop and another thread_fast is running a fast one that sends multiple signals while the other thread is still running it's slow method.....when the slow method from thread_slow returns to the event loop, will it process all the