For those who use Qt with QT_NO_CAST_FROM_ASCII enabled char*s and std::strings cannot be assigned to a QString or cast to a QString. This will not compile with QT_NO_CAST_FROM_ASCII enabled: QString foo( "Hello World" ); You could do this but Qt frowns upon it because it creates, "temporary QString objects and...
Why? It's because of the implementation of qDebug(). From the source code: inline QDebug &operator<<(QChar t) { stream->ts << '\'' << t << '\''; return maybeSpace(); } inline QDebug &operator<<(const char* t) { stream->ts << QString::fromAscii(t); return maybeSpace(); } inline QDebug &operator<<(const QString & t) { stream->ts << '\"' <<...
python-2.7,pyqt4,qstring,qlineedit
To convert one QString in Python 2, do this: self.name = unicode(self.new_label.text()) To automatically convert all QStrings, put this at the beginning of your code: import sip sip.setapi('QString', 2) # must be before any pyqt imports from PyQt4 import QtCore, QtGui If you do this, there's no need to keep...
OK, so I would do the following if I were you: Use QStringList instead of QVector<QString> as it has convenience methods that can be useful for you; it is also more common and hence comprehensive. You would spare one extra method call even in this case. Just use the removeOne()...
The pointer you return form convertQStr2char points to the internal buffer of the temporary std::string which is destroyed after the return. You thus use a dangling pointer and have undefined behavior. Note that changing the data pointed to by std::string::c_string() through said pointer also is UB. Your const_cast is a...
c++,qt,pattern-matching,qstring
This should work for valid numbers: QRegExp("(-?\\d+(?:[\\.,]\\d+(?:e\\d+)?)?)") edit: sry, messed up with the brackets, now it whould work....
As you found out yourself, you'll need QTextCodec for this. What you want to do should be as simple as this: QString src = "My test string"; QTextCodec *codec = QTextCodec::codecForName("Windows-1251"); QByteArray encodedString = codec->fromUnicode(src); ...
I was able to get it done with this: return QString::number(dwVolSerial); ...
There are two quick options: 1) Wrap your usage around with an external process and use QProcess. This will introduce an external wrapper. This will not allow you to process the error "sometimes" off-hand. You would need some external processing for that. QProcess process; process.start("wrapper"); process.waitForFinished(); qDebug() << process.readAllStandardError(); 2)...
You need to provide qrand with a suitable seed (usually at program startup). Try: QTime now= QTime::currentTime() ; qsrand( now.msec() ); You don't ask about this, but are you checking that fullName's length is not zero (as the program would attempt to divide by zero)? Or that it's not composed...
Indeed you are adding their address as p and n are pointer. try adding their value as: QString result = *p + *n; ...
I am unfamiliar with QString (and C++ for that matter!). However this could be one way that you can tackle it. Lets create a program to write the test attribute in a file called string.h5. Note that you can use either H5std_string or std::string. #include <iostream> #include <string> #ifndef H5_NO_NAMESPACE...
For using imread you have to pass a std::string to it . Mat imread( const std::string& filename, int flags=1 ); In your case image_names is vector<QString> so the correct code is : image = imread( image_names[i].toStdString()); ...
c++,regex,qt,qstring,qregularexpression
You could use two different methods for this, based on your need: split() section() main.cpp #include <QString> #include <QDebug> int main() { QString myString = "Last Name:SomeName, Day:23"; QStringList myStringList = myString.split(',').first().split(':'); qDebug() << myStringList.first() << myStringList.last(); return 0; } main.pro TEMPLATE = app TARGET = main QT = core...
Dialog2 should simply provide a signal containing the data you want to transfer to Dialog1 that gets emitted whenever Dialog2 is done with its action: Dialog1.cpp void Dialog1::on_pushButton_2_clicked() { Dialog2 dialog2; dialog2.setModal(true); dialog2.setWindowFlags(Qt::FramelessWindowHint); connect(&dialog2, &Dialog2::dataFetched, this, &Dialog1::updateData); // or Qt4 connect syntax // connect(&dialog2, SIGNAL(dataFetched(const QString&)), this, SLOT(updateData(const QString&)); //...
As far as I can see, QString does not support unicode characters greater than U+FFFF. In this test script you can see that it fails to calculate string size correctly for those characters: #include <QDebug> int main() { QList<QByteArray> list; list << QByteArray("a"); list << QByteArray("ö"); list << QByteArray("➜"); list...
QString selected = model2->filePath(index); does not set the variable in the (maybe same named) member OptionsDialog::selected. This creates a new local variable. If you have a member variable called selected then you should use it like this: void OptionsDialog::getData(const QModelIndex &index) { selected = model2->filePath(index); ... } ...
This line of code: QString str=0xFFFFFF5550464DAA0E; 0xFFFFFF5550464DAA0E is not a string. You're trying to assign a very big constant (9 bytes) number to a string. Note that 0xFF is not a string but a character with ASCII code 0xFF. With your second attempt you're on the right way: char cmd[9]={0xFF,0xFF,0xFF,0x55,0x50,0x46,0x4D,0xAA,0x0E};...
Qt's documentation on QString is pretty thorough and has a lot of examples on how to use it. You can find it here: http://doc.qt.io/qt-5/qstring.html In general, parsing an input string that could have mistakes in it is difficult (what would the expected behavior of an input string of "BarryDoyle" be?...
Here is a full example using rich text of QTextDocument. mainWindow.cpp: #include "mainWindow.h" void MainWindow::paintEvent(QPaintEvent*) { QPainter painter(this); QTextDocument td; td.setHtml("K<sub>max</sub>=K<sub>2</sub> · 3"); td.drawContents(&painter); } If you need to draw the text at specific point, translate the coordinate system of the painter before drawing: painter.translate(QPointF(50, 50)); mainWindow.cpp - Another solution:...
android,c++,qt,qstring,qtandroidextras
You need to use this method. QString QAndroidJniObject::toString() const Returns a QString with a string representation of the java object. Calling this function on a Java String object is a convenient way of getting the actual string data. So, I would write this if I were you: QAndroidJniObject string =...
pyqt,pyqt4,qstring,attributeerror,qgis
If Python2 is used with PyQt4, then classes like QString and QVariant will be available by default. However, the default for Python3 is to eliminate these classes and use the equivalent python types instead. These defaults can be overridden by using the sip module, like this: import sip # switch...
http://doc.qt.io/qt-4.8/qlineedit.html#text-prop textChanged is a signal that you can send when the text changes Use QString text() const instead Another useful method: modified : bool to check if the text was modified by the user Update to answer additional comment questions: It is best to declare all variables as private. Add...
Use format string to build the string for new name: QString newName("%1% - %2% - %3% (%4%)"); newName = newName.arg(f.tag()->artist().toCString()).arg(f.tag()->album().toCString()).arg(f.tag()->track()).arg(f.tag()->year()); ...
I think I have managed to reproduce your issue. in on_comboBox_Tabel_Select_currentIndexChanged there is a line: QStringList invoice = (QStringList() << "Invoice Number" << "Date Time" << "Total Purchased" << "Company Name" << "Company Owner"); In CreatQuery there is a line: QStringList invoice = (QStringList() << "Invoice_Number" << "Date_Time" << "Total_Purchased");...
There are 3 methods you will find useful: bool QString::endsWith (const QChar &c, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const; QString::remove(int position, int n); QString& replace(const QRegExp &rx, const QString & after) Just remove last character and you're set. You can either use remove() or replace() with a regexp detecting \n...
c++,qt,arguments,qstring,qmessagebox
All of the arg()s return a QString so the following should work: QMessageBox::information(0, "Full Name", QString("%1 %2").arg(first).arg(last)); For more information, you can check the documentation here....
c++,qt,qstring,qdatetime,qtime
Actually everything is ok for qt this value is 100 years earlier - 30/06/1915 https://www.unitjuggler.com/convert-time-from-ms-to-yr-365.html?val=3155756569078 QDate - wrong year I suggest using format "dd/MM/yyyy hh:mm:ss"...
You can retrieve the text after videoid= using QString::mid : QString str = "plugin://plugin.video.youtube/?action=play_video&videoid=4fVCKy69zUY"; QString strToFind = "videoid="; QString value = str.mid(str.indexOf(strToFind)+strToFind.length()); ...
To quote the documentation: You can convert the array to and from text based JSON through QJsonDocument. In other words, all you need to do is this: QJSonArray data; QJSonDocument doc; doc.setArray(data); QString dataToString(doc.toJson()); That's all there is to it!...
c++,qt,qtgui,qstring,qtreewidget
This solution does not avoid duplicate, so if you need that in the future, you could extend this piece of code with adding valiation for that. Anyway, this code produces the exact ame output for me that you have just described to wish to have. main.cpp #include <QTreeWidget> #include <QStringList>...
c++,qt,qstring,qtcore,qbytearray
I do not understand what you try to do with your code as it seems to be out of order, but the following code works for me: main.cpp #include <QString> #include <QByteArray> #include <QDebug> int main() { QByteArray buffer = "0A010A3C"; QString nburn_data; bool ok; for (int i = 0;...
The only way to use that idiom while still keeping your code understandable is if your function returns an object that is convertible to bool in a way that true indicates that you want to take the branch and false means that you do not care about it. Anything else...
Probably you can't do this, because you missed one >. So try this: #include<QDebug> //... private: QVector<QVector<QString> > *matrix = new QVector<QVector<QString> >; And in constructor: matrix->append(QVector<QString>() << "hello world"); qDebug() << "output: " << *matrix; But I think that you should allocate memory in constructor. For example: private: QVector<QVector<QString>...
I think you are looking for the indexOf method as follows: main.cpp #include <QString> #include <QDebug> int main() { QString substring("substring"); QString string("foosubstringbarsubstringbazsubstringhellosubstringworld"); for (int i = 0; (i = string.indexOf(substring, i)) != -1; ++i) qDebug() << string.mid(i); return 0; } main.pro TEMPLATE = app TARGET = main QT =...
Regarding memory management, QString uses copy-on-write, which is now explicitly forbidden in the C++ standard library. But there is a reason for that. The copy-on-write idiom performs worse in multi-threaded environment as it requires synchronization. This article discusses the problems in more details. Implementations of std::string on the other hand...
In your implementation the first map contains an inner map (your variable d). Imagine that you have another element in the d-map, say Age. Then you would have added another element: d->insert("Age", "42"); If you now would simply try to print the p->key() as in your attempt you can not...
python,python-3.x,import,qstring,pyqt5
In PyQt5, there is no QString and hence no need for QStringList. Any Qt API that would normally return a QString, will automatically return a Python string instead. Similarly, any Qt APIs that would normally return a QStringList will return a Python list containing Python strings. And the opposite also...
Remembering when I first needed to do this, the documentation can be a bit lacking and assumes you have knowledge of other QJson classes. To obtain a QString of a QJsonObject, you need to use the QJsonDocument class, like this: - QJsonObject jsonObj; // assume this has been populated with...
try getting rid of the semicolon after your loop. foreach(item, mylist)...
c++,performance,qt,qstring,itoa
You can try with QByteArray that shares same QString's interface but is more suitable for performance issues.I obtain 36 ms (qt 5.2 clang) vs. your original 57 ms (on my machine) with this code: QByteArray allDatab; foreach(const int & value, values) { allDatab += QByteArray::number(value); allDatab += '\n'; } QString...
No, the reinterpret cast is not safe and will not work on some platforms where the encoding is different. QChar is 16-bit and the internal encoding is UTF-16, but on Linux wchar_t is 32-bit UCS-4 encoding. The cast would happen to work (it's still undefined behaviour, but msc++ does not...
c++,qt,qt4,concatenation,qstring
You can use QSqlTableModel to show a table contents in a QTableView : QSqlTableModel * model = new QSqlTableModel(this,db); model->setEditStrategy(QSqlTableModel::OnFieldChange); model->setTable( "someTable" ); model->select(); ui->tableView->setModel( model ); But in case you want to use QSqlQuery you can make the query like : String myquery = QString("SELECT * FROM %1").arg(ui->lineEdit->text()); Or...
c++,qt,qstring,qtcore,qsettings
You have at least two ways to address this issue, all of them presented below: test.ini title="foo,bar" title_unquoted=foo,bar main.cpp #include <QSettings> #include <QDebug> int main() { QSettings settings("test.ini", QSettings::IniFormat); // Original issue qDebug() << settings.value("title_unquoted"); // 1st solution: join the strings qDebug() << settings.value("title").toStringList().join(','); // 2nd solution: use quotes in...
You need to use operator+, push_back, append or some other means for appending when using std::string, QString and the like. Comma (',') is not a concatenation character. Therefore, write this: if (ui->lineEdit_Company_Name->text().isEmpty()) ErrorLog = ErrorLog + "Company Name is empty\n"; if(ui->lineEdit_Company_Owner->text().isEmpty()) ErrorLog = ErrorLog + "Company Owner is empty\n"; Please...
If you search sources of Qt 4.8.6 you will find it declared here and defined here.
In regular expressions, \1 corresponds to the first matched group. Groups are parts of the regular expression in parentheses. For example matching the string "hello world" against regexp (hello)([.*]) will have \1 corresponding to "hello" and \2 to " world". In your second snippet, text1.replace(QRegExp("s"), "<b>\\1</b>"); you do not use...