Solved Passing QString to function.
-
how to pass QString in the following function ?
i am getting error saying : "no matching function for call to EyeCare::tr(const QString&)"QGroupBox *EyeCare::createBrightnessSettings(const QString name){ QGroupBox *brightnessSettings = new QGroupBox(tr(name)); ... } ... layout->addWidget(createBrightnessSettings("Brightness Settings"),0,0,Qt::AlignLeft); ...
thanks
-
Hi Ahti,
If you use
QGroupBox *brightnessSettings = new QGroupBox(name);
Then everything works?
the tr functions marks QStrings for translation. Here you use a variable. There is no point in translating variables, they are not visible to the user and don't need to be translated.
Eddy
-
@Eddy by using just
QGroupBox *brightnessSettings = new QGroupBox(name);
it throws error : "program has unexpectedly finished"
-
@Ahti
Can you debug your program to see where the problem starts? -
@Ahti said in Passing QString to function.:
how to pass QString in the following function ?
i am getting error saying : "no matching function for call to EyeCare::tr(const QString&)"QGroupBox *EyeCare::createBrightnessSettings(const QString name){ QGroupBox *brightnessSettings = new QGroupBox(tr(name)); ... } ...
Did you solve your error as listed in your first post?
The implementation is missing the apersand '&' and therefore you had initally the error message.
-
Hi,
It should rather be:
QGroupBox *EyeCare::createBrightnessSettings(const QString &name) //<< const reference as @koahnig suggested { QGroupBox *brightnessSettings = new QGroupBox(name); ... } ... layout->addWidget(createBrightnessSettings(tr("Brightness Settings")),0,0,Qt::AlignLeft); // the tr methods are usually put around text that you want to mark for translation. ...
-
@SGaist Still not working man
throwing error "program has unexpectedly finished"
and when i debug after a while it shows something wrong on this line :QGroupBox *brightnessSettings = new QGroupBox(name);
thanks
-
What does the stack trace tells you ?
-
Hi, also you could try (this is just a guess) to go via a normal QString, like this:
{ QString name2(name); QGroupBox *brightnessSettings = new QGroupBox(name2); ... }
-
here have a look of debug result:
https://postimg.org/image/6g1fp20zb/ -
Something fishy:
settingsBackground = constructFrame(this, settingsBackground, 10, 145, 640, 320);
Frankly the code itself looks like its doing pretty strange thing to setup the widget.
-
I don't think anything is fishy with constructFrame(); why would you think that ?
constructFrame definition:
QFrame* EyeCare::constructFrame(QWidget *parent, QFrame *frameName, int x, int y, int w, int h, QString style) { frameName = new QFrame(parent) ; frameName->setGeometry(x,y,w,h); if (!style.isEmpty()) frameName->setStyleSheet(style); return frameName ; }
I don't think there is anything wrong with it because i am using it with other places in my code and i have no issue with it.
What you think is strange please be specific ?
btw this is what i am trying to achieve with the code :
-
@Ahti Hi, looking at https://postimg.org/image/6g1fp20zb/ it seems that inside createBrightnessSettings you call createBrightnessSettings 2 times (one for "Day Mode" and one for "Night Mode") so that first time there are 2 calls, then 4, then 8, then 16 etc.... When recursive-calling yourself you need some mechanism to stop otherwise the program will crash :-(
-
@hskoglund but at the end it has a return statement which would return the "brightnessSettings" QGroupBox pointer this is where stopping mechanism for recursive call happens returning from every call would ultimately bring it out of the createBrightnessSettings() function .
-
Then why pass frameName as argument to that function ?
-
@SGaist I am creating more than one frame that is why i have to pass the name of the frame that i want to create.
like for example :
homeBackground = constructFrame(this,homeBackground,10,145,640,320) ; settingsBackground = constructFrame(this,settingsBackground,10,145,640,320) ; topSeperator = constructFrame(contactBackground,topSeperator,5,60,635,2,"background-color:white;") ; ...
-
This post is deleted! -
@Ahti well the recursiveness is still fatal, createBrightnessSettings("Night Mode",...) is never reached, instead createBrightnessSettings("Day Mode"... is calling itself many millions of times then the app crashes because of stack overflow.