PDA

View Full Version : Warning QString::arg() argument missing



quickNitin
16th November 2006, 04:17
greetings,
in the following code i am intializing a QString object


QString labelString;
...
labelString.clear();
labelString=QString("X%1 Y%2").arg(p.x()).arg(p.y()); //getting warning for this line
..


This code is resulting in warning

Warning: QString::arg() :Argument Missing : X1.2233 Y4.23232

I couldn't find out the cause of this. Sicne this code is used very frequently so its like getting 200 wanings in 1 sec.

quickNitin

jpn
16th November 2006, 08:00
I don't see anything wrong with that particular line. Are you 100% sure it's that line? :)

quickNitin
16th November 2006, 08:23
yes, i am.
I have tried to make diferent string. Like


labelString=QString("X%1f Y%2y).arg(p.x()).arg(p.y());

This results in 'f' succesiding numbers.

wysota
16th November 2006, 10:02
So what's wrong with it? What would you like to get?

quickNitin
16th November 2006, 10:40
its giving me what output i want but it is resulting in a warning also. Since this code is continuously used so many warnings which i want to avoid as i can't see other info on terminal.

wysota
16th November 2006, 10:43
But this code is correct (apart from a missing quote). Are you sure the warning is related to this line? Could you provide a minimal compilable example which reproduces the problem?

jacek
16th November 2006, 11:21
Maybe you use that labelString in arg() in some other place?

quickNitin
16th November 2006, 17:00
here is part of code generated this warning.



virtual void drawShape(QPainter &p)
{ //std::cout<<"|"<<mX<<" "<<mY;

//preparing label to be displayed
QString labelString;
if(mLabelIndex==0) {
labelString.clear();
labelString.setNum(mNo);
}
else if(mLabelIndex==1) {
QgsPoint p=toMapCoords(QPoint(mX,mY));
qWarning("Hello");
labelString=QString("X%1 Y%1").arg(p.x()+mapCenterX).arg(p.y()+mapCenterY);
qWarning("Bye");
}
QBrush brush(Qt::blue);
if(mId==0) /
{ p.save();
p.setBrush(brush);
p.drawEllipse(QRect(mX-3+mapCenterX,mY-3+mapCenterY,16,16));
p.drawLine(mX+mapCenterX, mY+mapCenterY, mX+mapCenterX, mY-10+mapCenterY);
if(mShowLabel)
p.drawText(QPoint(mX+5+mapCenterX, mY+5+mapCenterY) , labelString);
p.restore();
}
else if (mId==1)
{ brush.setColor(Qt::red);
p.save();
p.setBrush(brush);
p.drawEllipse(QRect(mX-3+mapCenterX, mY-3+mapCenterY,1 6,16));
p.drawLine(mX+mapCenterX, mY+mapCenterY, mX+mapCenterX, mY-10+mapCenterY);
if(mShowLabel)
p.drawText(QPoint(mX+5+mapCenterX, mY+5+mapCenterY), labelString);
p.restore();
}
else if(mId==2)
{ brush.setColor(Qt::yellow);
p.save();
p.setBrush(brush);
p.drawEllipse(QRect(mX-3+mapCenterX, mY-3+mapCenterY,6,6));
p.drawLine(mX+mapCenterX, mY+mapCenterY,mX+mapCenterX, mY-25+mapCenterY);
if(mShowLabel)
p.drawText(QPoint(mX+5+mapCenterX,mY+5+mapCenterY) ,labelString);
p.restore();
}
//updateCanvas();
}


This is virtual function of a class which is derived from a class inhertiting Q3CanvasItemRectangle.
Here same warning appears between 2 warnings . except this function i am nowhere using this string

regards
quickNitin

wysota
16th November 2006, 18:20
Could you please prepare a minimal compilable example reproducing the problem? It would be much easier for us all to notice the issue.

jacek
16th November 2006, 19:13
Look closely:
labelString=QString("X%1 Y%1").arg(p.x()+mapCenterX).arg(p.y()+mapCenterY);
You have %1 twice, not %1 and %2 as you have shown us earlier.