Skip to content

Commit

Permalink
fix deprecated QString sprintf()
Browse files Browse the repository at this point in the history
  • Loading branch information
lancos committed Mar 23, 2024
1 parent 4223d5d commit b1058b3
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 129 deletions.
2 changes: 1 addition & 1 deletion SrcPony/at90sxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ int At90sxx::QueryType(long &type)
detected_type = type;
}

detected_signature.sprintf("%02X-%02X-%02X", code[0], code[1], code[2]);
//snprintf(detected_signature, MAXMSG, "%02X-%02X-%02X", code[0], code[1], code[2]);
detected_signature = QString("%1-%2-%3").arg(code[0], 2, 16, QLatin1Char('0')).arg(code[1], 2, 16, QLatin1Char('0')).arg(code[2], 2, 16, QLatin1Char('0'));

rv = type ? OK : DEVICE_UNKNOWN;
}
Expand Down
4 changes: 2 additions & 2 deletions SrcPony/bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void BitFieldWidget::initWidget()
int bitOffset = vecInfo->at(i).bit;
lastBit = bitOffset;
QString sDes = vecInfo->at(i).ShortDescr;
itm->setText(0, QString().sprintf("Bit %d, ", bitOffset) + sDes);
itm->setText(0, QString("Bit %1, ").arg(bitOffset) + sDes);
if (vecInfo->at(i).LongDescr.length() > 0)
{
itm->setText(1, vecInfo->at(i).LongDescr);
Expand Down Expand Up @@ -309,7 +309,7 @@ void BitFieldWidget::setMaskBits(const QString &cMask)
// at begin of string only
mskName = "^" + mskName + "\\d+";

qDebug() << cMask << "converted to" << mskName << (bin) << localField << (Qt::dec);
qDebug() << cMask << "converted to" << mskName << (Qt::bin) << localField << (Qt::dec);

// search in QTreeWidget the names
for (idx = 0; idx < treeWidget->topLevelItemCount(); idx++)
Expand Down
6 changes: 3 additions & 3 deletions SrcPony/blockmdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ blockDialog::blockDialog(e2CmdWindow *bw, e2AppWinInfo *p, bool readonly, const
lblTo->setText(translate(STR_MSGNUMBLOCK));
lblVal->setText(translate(STR_MSGHIGHENDBLK));

QString str1 = QString().sprintf("%d", (int)((lock >> 4) & 0x0F));
QString str2 = QString().sprintf("%d", (int)(lock & 0x0F));
QString str3 = QString().sprintf("%d", (int)(fuse & 0x0F));
QString str1 = QString("%1").arg((int)((lock >> 4) & 0x0F)); //sprintf("%d", (int)((lock >> 4) & 0x0F));
QString str2 = QString("%1").arg((int)(lock & 0x0F)); //sprintf("%d", (int)(lock & 0x0F));
QString str3 = QString("%1").arg((int)(fuse & 0x0F)); //sprintf("%d", (int)(fuse & 0x0F));

txiFrom->setText(str1);
txiTo->setText(str2);
Expand Down
29 changes: 12 additions & 17 deletions SrcPony/e2awinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,8 @@ QString e2AppWinInfo::Dump(int line, int type)
{
long idx;
long upperlimit;
char lbuf[LINEBUF_SIZE + 1];
char tmpbuf[16 + 1];

if (!buf_ok)
{
Expand All @@ -1360,17 +1362,13 @@ QString e2AppWinInfo::Dump(int line, int type)
{
if (type == 0)
{
char tmpbuf[16 + 1];

for (int k = 0; k < hex_per_line; k++)
{
tmpbuf[k] = isprint(buffer[idx + k]) ? buffer[idx + k] : '.';
}

tmpbuf[hex_per_line] = 0;

linebuf.sprintf(" %06lX) %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X %s\n",
// snprintf(linebuf, LINEBUF_SIZE, " %06lX) %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X %s\n",
snprintf(lbuf, LINEBUF_SIZE, " %06lX) %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X %s\n",
idx,
buffer[idx + 0],
buffer[idx + 1],
Expand All @@ -1395,13 +1393,11 @@ QString e2AppWinInfo::Dump(int line, int type)
}
else if (type == 1)
{
linebuf.sprintf(" %06lX)", idx);
// snprintf(linebuf, LINEBUF_SIZE, " %06lX)", idx);
snprintf(lbuf, LINEBUF_SIZE, " %06lX)", idx);
}
else if (type == 2)
{
linebuf.sprintf(" %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X ",
// snprintf(linebuf, LINEBUF_SIZE, " %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X ",
snprintf(lbuf, LINEBUF_SIZE, " %02X %02X %02X %02X %02X %02X %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X ",
buffer[idx + 0],
buffer[idx + 1],
buffer[idx + 2],
Expand All @@ -1423,21 +1419,20 @@ QString e2AppWinInfo::Dump(int line, int type)
}
else
{
char tmpbuf[16 + 1];

for (int k = 0; k < hex_per_line; k++)
{
tmpbuf[k] = isprint(buffer[idx + k]) ? buffer[idx + k] : '.';
}

tmpbuf[hex_per_line] = 0;

linebuf.sprintf(" %s\n", tmpbuf);
// snprintf(linebuf, LINEBUF_SIZE, " %s\n", tmpbuf);
snprintf(lbuf, LINEBUF_SIZE, " %s\n", tmpbuf);
}

// linebuf[LINEBUF_SIZE - 1] = '\0';
lbuf[LINEBUF_SIZE] = '\0';
return QString(lbuf);
}
else
{
return "";
}

return linebuf;
}
28 changes: 14 additions & 14 deletions SrcPony/e2cmdw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@


#define STATUSBAR_FORM " Size 0 Bytes CRC 0000h "
#define STATUSBAR_PRINT " Size %5ld Bytes CRC %04Xh %c"
//#define STATUSBAR_PRINT " Size %5ld Bytes CRC %04Xh %c"


class e2AppWinInfo;
Expand Down Expand Up @@ -118,12 +118,12 @@ e2CmdWindow::e2CmdWindow(QWidget *parent) :
// to check this
fontSize = E2Profile::GetFontSize(); //sysFont.pointSize();

programStyleSheet = QString().sprintf("font-size: %dpt", fontSize);
programStyleSheet = QString("font-size: %1pt").arg(fontSize); //sprintf("font-size: %dpt", fontSize);

if (fontSize == -1)
{
fontSize = sysFont.pixelSize();
programStyleSheet = QString().sprintf("font-size: %dpx", fontSize);
programStyleSheet = QString("font-size: %1px").arg(fontSize); //sprintf("font-size: %dpx", fontSize);
}

if (programStyleSheet.length() > 0)
Expand Down Expand Up @@ -1464,20 +1464,19 @@ void e2CmdWindow::selectFontSize(QAction *mnu)
// for lang menu and for fontsize menu
if (sz == -1)
{
programStyleSheet = QString().sprintf("font-size: %dpx", fontSize);
programStyleSheet = QString("font-size: %1px").arg(fontSize); //sprintf("font-size: %dpx", fontSize);
}
else
{
programStyleSheet = QString().sprintf("font-size: %dpt", fontSize);
programStyleSheet = QString("font-size: %dpt").arg(fontSize); //sprintf("font-size: %dpt", fontSize);
}

E2Profile::SetFontSize(fontSize);

QString sSheet2 = QString("QMenu { %1; }").arg(programStyleSheet);

setStyleSheet(programStyleSheet);

// langMenu->setStyleSheet(sSheet2);
//QString sSheet2 = QString("QMenu { %1; }").arg(programStyleSheet);
//langMenu->setStyleSheet(sSheet2);

setFontForWidgets();
}
Expand Down Expand Up @@ -2912,7 +2911,7 @@ int e2CmdWindow::CmdReadCalibration(int idx)
if (verbose == verboseAll)
{
QString str;
str = translate(STR_MSGREADCALIBOK) + QString().sprintf(": 0x%02X (%d)", rval, rval);
str = translate(STR_MSGREADCALIBOK) + QString(": 0x%1 (%2)").arg(rval, 2, 16, QLatin1Char('0')).arg(rval); //sprintf(": 0x%02X (%d)", rval, rval);

QMessageBox note(QMessageBox::Information, "Calibration", str, QMessageBox::Ok);
note.setStyleSheet(programStyleSheet);
Expand Down Expand Up @@ -3190,7 +3189,7 @@ int e2CmdWindow::CmdProgram()
if (verbose != verboseNo)
{
QString str;
str = translate(STR_MSGPROGRAMFAIL) + QString().sprintf(" (%d)", result);
str = translate(STR_MSGPROGRAMFAIL) + QString(" (%1)").arg(result); //sprintf(" (%d)", result);

QMessageBox note(QMessageBox::Critical, "Program", str, QMessageBox::Close);
note.setStyleSheet(programStyleSheet);
Expand Down Expand Up @@ -4333,7 +4332,7 @@ int e2CmdWindow::CmdRunScript(bool test_mode)
if (verbose != verboseNo)
{
QString str;
str = translate(STR_MSGPROGRAMFAIL) + QString().sprintf(" (%d)", result);
str = translate(STR_MSGPROGRAMFAIL) + QString(" (%1)").arg(result); //sprintf(" (%d)", result);

QMessageBox note(QMessageBox::Critical, "Script information", str, QMessageBox::Close);
note.setStyleSheet(programStyleSheet);
Expand Down Expand Up @@ -5278,7 +5277,8 @@ void e2CmdWindow::UpdateStatusBar()
if (awip)
{
QString buf;
buf.sprintf(STATUSBAR_PRINT, GetDevSize(), awip->GetCRC(), awip->IsBufChanged() ? '*' : ' ');
//buf.sprintf(STATUSBAR_PRINT, GetDevSize(), awip->GetCRC(), awip->IsBufChanged() ? '*' : ' ');
buf = QString(" Size %1 Bytes CRC %2h %3").arg(GetDevSize(), 5).arg(awip->GetCRC(), 4, 16, QLatin1Char('0')).arg(awip->IsBufChanged() ? '*' : ' ');
lblEEPInfo->setText(buf);
lblStringID->setText(awip->GetStringID());
}
Expand Down Expand Up @@ -6481,7 +6481,7 @@ void e2CmdWindow::Print()
t << QString("File: " + GetFileName());
t << QString("Device: " + awip->GetStringID());
t << QString("Note: " + awip->GetComment());
t << QString().sprintf("Size : %ld Bytes CRC: %04X", GetDevSize(), awip->GetCRC());
t << QString("Size : %1 Bytes CRC: %2h").arg(GetDevSize()).arg(awip->GetCRC(), 4, 16, QLatin1Char('0')); //sprintf("Size : %ld Bytes CRC: %04X", GetDevSize(), awip->GetCRC());

for (; k < no_line && curRow < 66; k++)
{
Expand All @@ -6501,7 +6501,7 @@ void e2CmdWindow::Print()

doc.documentLayout()->setPaintDevice(&printer);

doc.setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number
//doc.setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number
doc.setHtml(str);
doc.print(&printer);
}
Expand Down
Loading

0 comments on commit b1058b3

Please sign in to comment.