Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. qstring
    Log in to post

    • SOLVED how to get a correct result QString with SQL example
      General and Desktop • sql qstring arg qstring arg sql like • • Artem1  

      3
      0
      Votes
      3
      Posts
      22
      Views

      @JonB thanks!
    • UNSOLVED Easiest way to get substring from QString in Qt
      General and Desktop • c++ qstring qstringlist regex substring • • learnist  

      2
      0
      Votes
      2
      Posts
      41
      Views

      Hi, One possible way is to use QRegularExpression::match or since it looks like xml, you can use QXmlStreamReader.
    • UNSOLVED How to change the font and color of QString?
      General and Desktop • c++ qt 5.4 qstring • • learnist  

      12
      0
      Votes
      12
      Posts
      315
      Views

      @JonB tests are in order ! It would indeed be simpler. As I miswrote (and fixed) it's possibly a memory issu :-).
    • UNSOLVED Qt4 and Qt5 compatibility issue with QDatastream and QDateTime
      General and Desktop • qt5 qt4 qstring qdatastream qdatetime • • johnyang  

      2
      0
      Votes
      2
      Posts
      65
      Views

      Now I realized I have to set QDataStream::setVersion to QDataStream::Qt_4_7. I think the problem is solved.
    • SOLVED Storing QString constants without global static non-pod values
      General and Desktop • qstring static string global non-pod • • Linus Jahn  

      5
      0
      Votes
      5
      Posts
      825
      Views

      Thanks for your replies. It probably doesn't matter at all, because the only result will be that the library is a few micro seconds faster at runtime / at load time. The reason is probably rather a psychological one than a real performance issue. -- I'd like to write clean code, use the ideal way and don't want to see warnings when running i.e. clazy on my code. When looking at performance there are probably other issues that have a greater impact on the performance. I actually tested it now: Test 1: Runtime usage #include <QString> const char *xmlns = "urn:ietf:xml:ns:xmpp-sasl"; // OR: const QString xmlns = QStringLiteral("urn:ietf:xml:ns:xmpp-sasl"); int main() { for (int i = 0; i < 1e9; i++) { // Option A: QString text(xmlns); // Option B: appending 'a' QString xmlnsPlusA = QString(xmlns) + 'a'; } } QStringLiteral char* A: QString( ), QStringLiteral is implicitly-shared 0.5 s 52 s B: appending 'a' 27 s 91 s -> The relative difference is high, but the absolute numbers are not relevant: You need to convert about 500 kB (about 20k comparable strings), so that this takes more than 1 ms and gets a performance problem in a GUI application. Test 2: Start-up time I also created a test binary with 10k global static constants (all with the same content): QString (cast from char *) QStringLiteral char * compile time 3 s 3.5 min < 1 s binary size (stripped) 410 kB 1270 kB 320 kB time to run (10k times) 33 s 23 s 19 s I guess the QStringLiteral binary takes longer to run, because it is larger and only partially, because of the non-POD CTORs. -> Using QStringLiteral has a slightly larger impact on the execution time than I've expected, but this is still not relevant since you usually have less than 10k global static strings and you only load the binary once instead of 10000 times. As long as you're not developing for an arduino this has probably no relevance. As expected the usage of QStringLiteral makes the binary a bit larger, the start-up time a little little bit larger, but is faster compared to casting from ascii everytime at runtime. I'll see if I can do anything with QArrayData, not because it's important, just for fun.
    • SOLVED How to remove quotes and eol characters from QString?
      General and Desktop • qstring new line carriage return quotes • • emp1953  

      9
      0
      Votes
      9
      Posts
      568
      Views

      @emp1953 said in How to remove quotes and eol characters from QString?: There is still the annoying little "square" shape after every item in the QListWidget. QFile::readLine() behaves different on Windows and Linux, your can read that in the docu. On Linux it assumes \n line endings, on Windows \r\n ones, which it replaces with \n. Your file is none of these, it has mixed endings. If you want to use it in Linux, you have to normalize the line endings first. Otherwise readLine() will not do what you expect and every following procedure will fail. The square bracket you see is probably the \r char, which cannot be displayed otherwise. From within the Qt Creator development environment it does in fact compile without warnings and outputs an executable. But not the code you posted above. This code is invalid and no compiler will accept it. Double check what you are doing. Regards
    • SOLVED How do I append characters of a QString to another QString in a neat way?
      General and Desktop • qstring time appending • • legitnameyo  

      5
      0
      Votes
      5
      Posts
      162
      Views

      @JKSH said in How do I append characters of a QString to another QString in a neat way?: Anyway, you could simplify the whole thing: QDateTime now = QDateTime::currentDateTime(); QString yyyy = now.toString("yyyy"); QString MM = now.toString("MM"); QString dd = now.toString("dd"); QString HH = now.toString("HH"); QString mm = now.toString("mm"); QString ss = now.toString("ss"); This is ideally the best general solution, IMHO
    • UNSOLVED Number of characters that fit into given width
      General and Desktop • qstring qfontmetrics • • Arthur Araruna  

      4
      0
      Votes
      4
      Posts
      553
      Views

      @VRonin said in Number of characters that fit into given width: Something like http://doc.qt.io/qt-5/qfontmetrics.html#elidedText ? Turns out it will not work for me. The QString returned includes the ellipsis and there is no way to avoid them, because passing Qt::ElideNone means "do not truncate" instead of "omit the ellipsis" (as I feared).
    • SOLVED Correct way to convert a QString to a const wchar_t* with L prefix
      General and Desktop • qstring • • robro  

      7
      0
      Votes
      7
      Posts
      2254
      Views

      Here are a couple of variations that worked for me in Visual Studio 2017: diac = QStringLiteral("ÀÉ"); uint chin[] = {0x4E83, 0}; // L'亃' diac2 = QString::fromUcs4(chin); wchar_t chinW[] = {L'亃', 0}; wchar_t *chinW2 = L"亃"; diac3 = QString::fromWCharArray(chinW2); // also chinW diac += diac2 + diac3; Sorry I just realized you want to go the other way.
    • SOLVED Using QSignalMapper instead of Signals and slots
      General and Desktop • qt creator signal & slot qstring qsignalmapper • • Kushan  

      4
      0
      Votes
      4
      Posts
      922
      Views

      @Kushan Simple C++: class Dialog2 : public QDialog { Q_OBJECT private slots: void receiveValue2 (QString val) public: QString Value explicit Dialog2(QWidget *parent = 0); ~Dialog2(); void setValue(const QString &val) { Value=val; } private: Ui::Dialog2 *ui; }; ... void MainWindow::on_pushButton_clicked() { value=ui->line_Edit->text(); Dialog dialog1; dialog1.setValue(value); }
    • UNSOLVED Index out of range error
      General and Desktop • qstring qstringlist runtimeerror concatanation • • Lasith  

      5
      0
      Votes
      5
      Posts
      928
      Views

      Hi Normally its the that can give "index out of range error" not when inserting ?
    • SOLVED concatanating qtablewidget items into string incorrect
      General and Desktop • qtcreator qstring qstringlist concatanation • • Lasith  

      3
      0
      Votes
      3
      Posts
      713
      Views

      @SGaist Dman that was silly mistake :(
    • UNSOLVED Getting the rows in a qtablewidget to new lines in a textfile in qt c++
      General and Desktop • c++ qtcreator qstring row new line • • Lasith  

      4
      0
      Votes
      4
      Posts
      1257
      Views

      While I'm here, you can use https://github.com/VSRonin/Qt-Model-Serialisation/tree/dev CsvModelSerialiser modelSaver; modelSaver->setModel(ui->tableWidget_2->model()); modelSaver->setCsvSeparator(" "); QFile mFile("C:/Users/Desktop/Qt/textfiles/test.txt"); modelSaver->saveModel(&mFile);
    • SOLVED ASSERT on QString line 885 return false size by read line by line of a 125MB file.
      General and Desktop • qstring • • patrik08  

      8
      0
      Votes
      8
      Posts
      1558
      Views

      Hi ... oh yes i read line by line.. each line have other language to detect.. wich so much text in over 200 or more language... google the file name test_shuffle_1000_48_666.utf8.gz i tested for https://github.com/pehohlva/QCLD2 for language detection .. the error was unclosed array cycle that fill ram... not QString... have incremented all line... :-) & must go in assert -
    • SOLVED Extract a QString with a regular expression.
      General and Desktop • qstring qregexp split extract • • Patou355  

      12
      0
      Votes
      12
      Posts
      7295
      Views

      One small note, you are wasting CPU cycle here. The QRegularExpressionMatchIterator returns only match objects that contains a match thus the if is useless.
    • SOLVED Tag html on QString not applied when contains "\n"
      General and Desktop • qstring html color • • helenebro  

      2
      0
      Votes
      2
      Posts
      799
      Views

      Then use "<br>" instead of "\n"
    • SOLVED QRegExp replace every second character with a whitespace (blank)?
      General and Desktop • qstring regex • • Opa114  

      3
      0
      Votes
      3
      Posts
      700
      Views

      ah thanks - using \\1 instead of $1 works as i want it. And thanks for the other solution with the For-Loop.
    • Matching a regular expression in string.
      General and Desktop • qstring qregexp • • NIXIN  

      4
      0
      Votes
      4
      Posts
      7677
      Views

      Sure, they are in the docs: http://doc.qt.io/qt-5/qregexp.html#code-examples indexIn() method should interest you in this case.
    • UNSOLVED Limitation of string length for qDebug() output?
      General and Desktop • qstring qdebug string limit qtcreatorbug-17 • • koahnig  

      8
      0
      Votes
      8
      Posts
      3285
      Views

      The reason for this is a GDB limitation on Windows. See QTCREATORBUG-24649 for more information. Regards
    • SOLVED How can i convert Utf-8 encoding to normal text
      General and Desktop • qstring text utf-8 • • Rohith  

      15
      1
      Votes
      15
      Posts
      12279
      Views

      @Rohith instead of converting the unicode string to the escaped characters send it directly in binary form. When you have a QString already you can call QString::toUtf8() and send the returned QByteArray directly. On the client its enough to do QString::fromUtf8( receivedUtf8ByteArray.constData() ) It depends how you implemented the transfer. But theoretically it should be enough to replace your unicode escaping code on the server with this approach.
    • SOLVED Unable to generate MD5 of a QString
      General and Desktop • qstring crypto qcryptographich hash • • Qjay  

      3
      0
      Votes
      3
      Posts
      2584
      Views

      Thanks !! I just figured it out after reading Docs !! Thanks for replying (y)
    • SOLVED DBus reply data accessed via QString
      General and Desktop • qstring qlist qvariant dbus method • • amonR2  

      22
      0
      Votes
      22
      Posts
      7410
      Views

      @micland WOOW!!! Thank you sooo much micland!! It works!!! I tried a code similar to yours but some data were missing. Just needed to do a very tiny modification on your code: qDebug() << key << value.variant().toString(); or directly qDebug() << value.variant().toString(); Except it, it is perfect! Thank you again. @micland said: I have no clue why the qdbusviewer of Qt 5.6 is unable to call the DBus method but the code snippet above is working fine. I hope it is going to change as I intend to use it or the 5.7 version very soon. Cheers again.
    • SOLVED how to print 'basic_string<char> std::string' in qt?
      General and Desktop • c++ qstring qt5.5.1 string qt creator 3.6 • • Mandar Khire  

      11
      0
      Votes
      11
      Posts
      10896
      Views

      @Mandar-Khire If you change your basic C++ program like this then you will not see the output as well: #include <iostream> using namespace std; int main() { cout << "Hello World by C++!"; while(true); return 0; } Qt uses an event loop, so after executing void Widget::on_showButton_clicked() { cout << "Hello World by QT!"; } your program is "sleeping" in the event loop and not flashing cout buffer.
    • SOLVED Convert QString to string
      General and Desktop • qt5.6 qstring string convert • • Punit  

      5
      0
      Votes
      5
      Posts
      16133
      Views

      Hi @Wieland , I did not test the code. But Yes, you are right. I tested @Punit 's code after my comment. It worked for me too(missed only that semicolon).
    • UNSOLVED QString <not accessible > on qt4.7
      Mobile and Embedded • qstring 4.7 • • sharethl  

      1
      0
      Votes
      1
      Posts
      621
      Views

      No one has replied

    • SOLVED QString to ASCII QByteArray
      General and Desktop • qstring • • kshegunov  

      4
      0
      Votes
      4
      Posts
      16038
      Views

      If .toAscii() worked for you before, you can savely use .toLatin1(), too, and ^Z will be preserved.
    • SOLVED [QString] Implicit Sharing
      General and Desktop • qstring deep copy • • HAWK0044  

      3
      0
      Votes
      3
      Posts
      844
      Views

      Thank you a lot for quick and exact answer!
    • UNSOLVED New line (\n) doesn't work
      General and Desktop • qstring • • gabor53  

      3
      0
      Votes
      3
      Posts
      4488
      Views

      Thank you.
    • SOLVED ASSERT occurs on a.at(5).isNull()
      General and Desktop • qstring • • rbmisc  

      2
      0
      Votes
      2
      Posts
      821
      Views

      The assertion is expected behaviour for QString::at The position must be a valid index position in the string (i.e., 0 <= position < size()). Instead, you should do something like: if (5 >= a.size()) { out << "Outside the range of the string" << endl; } Cheers.
    • SOLVED Filter by Date on a SQLITE
      General and Desktop • sqlite qstring query qdate date • • cxam  

      4
      0
      Votes
      4
      Posts
      4916
      Views

      @the_ @SGaist Hi, I managed to solve it on my own by encoding the date to a JulianDate and using juliandate on my db so it's much easier to compare and so. Thanks for your help.
    • SOLVED TextChanged variable unreachable ?
      General and Desktop • qstring qlineedit variable qlinedit • • cxam  

      3
      0
      Votes
      3
      Posts
      907
      Views

      @mrjj Thanks Mrjj :) it went perfect, you're awesome haha ;)
    • UNSOLVED Qstring is not a class or namespace name
      General and Desktop • error qstring c2653 • • TIG_Slayer1  

      3
      0
      Votes
      3
      Posts
      2305
      Views

      @kshegunov Thank you so much for the help! Such a simple mistake
    • UNSOLVED [SOLVED] QTabWidget tabName and qplaintextedit::textChanged() signal problem
      General and Desktop • qstring qtabwidget qplaintextedit • • takoo  

      31
      0
      Votes
      31
      Posts
      6722
      Views

      @mrjj that is right :D
    • UNSOLVED UI isn't shown when worker thread runs.
      Mobile and Embedded • qt5.5 signal & slot qstring user interface constructor • • Zola  

      8
      0
      Votes
      8
      Posts
      1800
      Views

      I solved my problem with not calling parseFunction in its own class constructor but with signals and slots in mainwindow.cpp file: connect(xml, SIGNAL(started()), first, SLOT(parseFunction()));
    • UNSOLVED Ignore unused args in QString::arg
      General and Desktop • qstring arg • • PhTe  

      3
      0
      Votes
      3
      Posts
      3592
      Views

      Thanks, i think i will do it so :)
    • UNSOLVED if used link , please . help me ??????????????????/
      Qt WebKit • qstring webkit help use if • • qt_5.x  

      2
      0
      Votes
      2
      Posts
      839
      Views

      Hi, As already asked, stop reposting the same question. Duplicates Closing this one.
    • Split hex encoded string
      General and Desktop • qstring qstringlist regex hex format • • azarubkin  

      2
      0
      Votes
      2
      Posts
      1077
      Views

      You can use a regular expression in a loop: QString s = "806982"; QRegExp re("([\\da-fA-F]{2})"); // exactly 2 hex digits QStringList l; int pos = 0; while ((pos = re.indexIn(s, pos)) != -1) { l << re.cap(1); pos += re.matchedLength(); }
    • How to force QString to serialize as UTF-8?
      General and Desktop • qstring qdatastream • • Resurr3ction  

      1
      0
      Votes
      1
      Posts
      839
      Views

      No one has replied

    • Не могу разобраться с textedit
      Russian • qstring qstringlist textedit • • steel24  

      2
      0
      Votes
      2
      Posts
      3212
      Views

      #include <QApplication> #include <QTextEdit> #include <QDebug> #include <QPalette> #define SET_BG_COLOR(edit, color)\ QPalette palette;\ palette.setColor(QPalette::Base, (color));\ palette.setColor(QPalette::Text, (color) == Qt::red ? Qt::white : Qt::black);\ (edit).setPalette(palette); // вот функция которая тебе нужна // возвращает: // -1: одна из строк пустая // 0: не нашли // 1: нашли int findText(const QString &textEdit, const QString &textFile){ // если один из текстов пустой if(!textEdit.length() || !textFile.length()){ return -1; } // означает: читать строку до символа разделителя, включает (пробел, -, _) QRegExp rx("[^ \\-_]*"); // находим строку до разделителя if (rx.indexIn(textEdit) != -1){ // отрезаем строку до разделителя" QString find = textEdit.left(rx.matchedLength()); // производим поиск в тексте return textFile.indexOf(find) != -1; } return 0; } int main(int argc, char *argv[]) { QApplication app(argc, argv); const QString textFile = "Помогите плиз, нужно с текста в textEdit выбрать " "слово и проверить есть ли такое слово в " "файле, собственно мне нужна помощь с textEdit не могу " "понять как взять из него слово до " "разделительного символа и ввести его в переменную типа QString"; QTextEdit edit; // при изменении текста будем делать проверку QObject::connect(&edit, &QTextEdit::textChanged, [&edit, &textFile](){ QColor color = Qt::white; switch(findText(edit.toPlainText(), textFile)){ case -1: break; // цвет по умолчанию белый case 0: color = Qt::red; break; case 1: color = Qt::green; break; } SET_BG_COLOR(edit, color); }); edit.show(); return app.exec(); }