qstring

Appending number to QString with arg() , is there better ways?

…衆ロ難τιáo~ 提交于 2019-12-12 11:03:11
问题 I've been using QString::number () to convert numbers to string for long time , now i'm wondering if there's something better than following: int i = 0; QString msg = QString ("Loading %1").arg (QString::number (i)); How can i spare QString::number () ? i checked document , seems only "%1" is applicable , no other stuff like "%d" could work 回答1: You can directly use arg() like this int i = 0; QString msg = QString ("Loading %1").arg(i); Qt will automatically convert it for you 回答2: QString's

QString to short using toShort

自作多情 提交于 2019-12-12 06:47:38
问题 I want to convert QString to short.when I try this code ui->lineEdit->text().toShort(); It works well for text = 20 but it returns "0" for value = 20.5. but I need value = 20. how can I solve it? 回答1: The reason that 0 is returned is because a decimal point is an invalid character for the short data type. If you want to be able to convert floating-point numbers from QString to integers, you need to convert your text to a float or double first, then use normal rounding/truncation to convert to

QtCreator 2.3--Lost ability to see QString contents in debugger

我的梦境 提交于 2019-12-12 06:25:03
问题 So I recently upgraded to QtCreator 2.3 (and want to keep it for its QtQuick support) and initially debugger performance slowed to an unusable crawl (though I could still see QString contents). Googling around led me to install gdb 7.3.1, the latest stable release at this time, and that happily brought debugger stepping speed back up to usable levels. But now the debugger won't display the contents of a QString, just the address of the char array, and a lot of private members that don't tell

Watch a QStringList for new items

寵の児 提交于 2019-12-12 05:37:30
问题 I am working on a data logger in QT framework. I Intend to save log strings to files and print to the console in a separate watcher thread. In that separate thread I need to watch my QStringList for new items added. If there are new items I deque them and log. I was wondering what is the mechanism used for this in Qt framework. In STD lib i used condition_variable for this task like this: /*! * \brief puts a \ref logline_t object at the end of the queue * @param s object to be added to queue

Replace spaces in QString with backslash spaces

我怕爱的太早我们不能终老 提交于 2019-12-12 04:28:58
问题 I need to replace spaces in a QString with backslash spaces. I have: QString myPath = /home/matt/my file.txt I need: QString myPath = /home/matt/my\ file.txt I tried using myPath.replace(" ", "\ "); but unfortunately the compiler interrupts this as an escape sequence. 回答1: The compiler uses \ as an escape character in strings. You will need two backslashes. myPath.replace(" ", "\\ "); 来源: https://stackoverflow.com/questions/41033583/replace-spaces-in-qstring-with-backslash-spaces

Qt char* to QString

白昼怎懂夜的黑 提交于 2019-12-12 03:38:57
问题 I am trying to convert char* to QString . It should be a trivial task but the problem is, I am having the following input: item char [512] "N" char [512] [0] 78 'N' char [1] 0 '\0' char [2] 73 'I' char [3] 0 '\0' char [4] 70 'F' char [5] 0 '\0' char [6] 84 'T' char [7] 0 '\0' char [8] 89 'Y' char [9] 0 '\0' char [10] 0 '\0' char Notice the null character after each character '\0'. Simply trying to convert it just yields the string "N" where as it should result into string "NIFTY" . I am not

AttributeError: 'QString' object has no attribute 'rfind'

荒凉一梦 提交于 2019-12-12 03:25:20
问题 My application runs fine in one computer but when I run the same application in another I get the error: Traceback (most recent call last): File "./th.py", line 98, in browse_file2 self.textEdit_2.append(str(os.path.basename(p))) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 121, in basename i = p.rfind('/') + 1 AttributeError: 'QString' object has no attribute 'rfind' I have seen a similar error here. According to this, I need to typecast parameter

QT实现日志系统

荒凉一梦 提交于 2019-12-12 02:38:12
功能: 可以把简单输出信息显示到QTextEdit上面。 可以把详细输出信息保存到文件中(为了避免多次打开文件进行读写,我用了双缓冲和线程)。 主要文件1:SysMessage.h #ifndef SYSMESSAGE_H #define SYSMESSAGE_H #include <qthread.h> #include <qtextedit.h> class SysMessage : QThread { public: void run(); void write_message(); /* Out message to file and UI. * */ static void open_sys_message(QTextEdit *e); static void close_sys_message(); static void SysMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg); private: SysMessage(); ~SysMessage(); unsigned int message_buf_size; char *message_buf_A;//take turns using buf char *message_buf_B; char

cannot convert from int & missing default parameter for parameter 1

一笑奈何 提交于 2019-12-12 01:48:19
问题 I am developing new project in Qt with existing MFC project . SO in MFC I have a function which uses SYSTEMTime and return CString. example CString getTimestampString( void ) { SYSTEMTIME systemTime; CString datestr; GetSystemTime( &systemTime ); datestr.Format( "%02i/%02i/%04i, %02i:%02i:%02i", systemTime.wDay, systemTime.wMonth, systemTime.wYear, systemTime.wHour, systemTime.wMinute, systemTime.wSecond ); return ( datestr + "; " + get_file_version_info().ProductName.c_str() + ", " + get

Qt QGraphics类应用——地图缩放选点

杀马特。学长 韩版系。学妹 提交于 2019-12-11 12:59:31
功能:   1、地图缩放   2、显示鼠标点经纬度 需求:   1、一张地图   2、地图左上角经纬度和地图右下角经纬度 成品: 代码: mapwidget.h #ifndef MAPWIDGET_H #define MAPWIDGET_H #include <QGraphicsView> #include <QLabel> #include <QMouseEvent> class MapWidget : public QGraphicsView { Q_OBJECT public: MapWidget(); void readMap(); QPointF mapToMap(QPointF point);//用于场景坐标与地图坐标转换 protected: void drawBackground(QPainter *painter, const QRectF &rect); void mouseMoveEvent(QMouseEvent *event);//拖动 void wheelEvent(QWheelEvent *event); //缩放 private: QPixmap map; qreal zoom; QLabel *sceneCoord,*viewCoord,*mapCoord; double x1,x2,y1,y2; int scaleValue; }; #endif