WxWidgets CheckListBox getting value issue - wxwidgets

I have a problem with WxWidgets version 3.0.2. Currently I'm trying to get the value of a 'ChecklistBox' with index number 0.
It seems to work, however I can't get it to fill a string variable from C++.
I tried a lot of things, such as .ToString(), .mb_str(), (string)varname, etc.
The code I am using to get the value which I presume works, but returns a non 'string' result, so I can't use it in my C++ code... (at least not yet..)
The Code I use to get the value of index number 0 returns no errors:
CheckListBox = new wxCheckListBox(this, CHECKBOX1, wxDefaultPosition, wxSize(208,63), 0, 0, 0, wxDefaultValidator, _T("CHECKBOX1"));
CheckListBox->GetItem(0); //Seems to work (at least gives no errors)
String Test = CheckListBox->GetItem(0); //Fails
Error returned: conversion from ‘wxOwnerDrawn’ to non-scalar type std::__cxx11::string {aka std::__cxx11::basic_string}|*
Simple test such as the following work since I see 'Test' added to the CheckListBox:
CheckListbox->Check(CheckListBox->Append("Test"));
Thanks for any advice!

I can't see GetItem(idx) in CheckListBox.
Perhaps you are looking for virtual wxString GetString (unsigned int n) const which is inherited from wxListBox.

Related

libpqxx prepared statements nonnull checks for pointer types

I'm a newbie to SQL overall and libpqxx as well.I'm trying to build a basic application where I just need to use prepared statements to execute very simple jobs.
I have started with libpxx 4.0 version and I implemented codes like this:
pqxx::work txn( *conn );
auto result = txn.prepared( "my_insert" )( x->getId( ), x->isIdSet( ) )( x->getUser( ), x->isUserSet( ) )(x->getCreatedAt( ), x->isCreatedAtSet( ) ).exec( );
txn.commit();
Now I had to change to version 6.4 and realized the prepared function is deprecated and I should use the exec_prepared function. Okay. BUT I'm really missing the "nonnull" condition. For certain reasons I'm working with a lot of pointers and I need a convenient way to pass on these values to the database API. I could write something like:
auto result = txn.exec_prepared( "my_insert", (x->isIdSet() ? std::to_string(x-getId()) : "null"), ....);
This could work in some cases but when I try to insert "null" as string into a smallint field I get an sql error (what is reasonable though).
As types differ I can't use the ?: operator to return string/int/etc... on true branch and nullptr on false branch.
I couldn't find a proper documentation about the library. They have a doc here but if you want to find out more about a certain function there's literally nothing there.
Honestly even the deprecated .prepared(...) function doesn't work properly with 6.4 for me. I tried txn.prepared("whatever")(y->z->getA(), y->z != nullptr).exec() form and I got segmentation fault when y was a valid non-null pointer type and z was null-pointer. I expected the function wouldn't touch the value before checking on the condition but apparently it's not the case.
I have a prepared statement with 8 parameters 6 of them being a pointer type (shared_ptr) and it would be extremely messy if I have to come up with a ridiculous solution to check all the parameters one-by-one and having to write 200 lines just to be able to call this function properly.
Anyone out there having a proper solution? As I mentioned I'm a newbie so I might miss an important part there. Help me out please ^^
I know this question is old. But here's what you do:
const auto& id{ x->isIdSet()
? std::optional<std::string>{x-getId()} : std::nullopt };
auto result{ txn.exec_prepared("my_insert", id, ....) };

Can you overcome vb.net from HttpContext.Current.Request.Url.AbsoluteUri and HttpContext.Current.Request.RawUrl using different case symbols?

The code below throws a server error:
Option Compare Text
Dim strAppURL As String = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf(HttpContext.Current.Request.RawUrl))
System.ArgumentOutOfRangeException: 'Length cannot be less than zero.
because:
HttpContext.Current.Request.Url.AbsoluteUri =
"http://localhost:22222/Dev/Canvas.aspx?&act=ccis&filn=002+(Ene+D%C4%83nu%C5%A3).png"
and
HttpContext.Current.Request.RawUrl =
"/Dev/Canvas.aspx?&act=ccis&filn=002+(Ene+D%c4%83nu%c5%a3).png"
Observe the symbols are different: %C4%83 vs. %c4%83 and %C5%A3 vs. %c5%a3
Just in case this issue was encountered before, I would welcome some help in handling it outside the code (other than using ToUpper() or ToLower() methods). I would prefer an application level directive. Thank you.

Expected expression error assigning value in Objective-C

I am a new Objective-C programmer and I am working on a project.
I created a function which returns a float value and I declared some variables into it as shown here :
-(float)WN8Calculation{
int avgDAMAGE,avgFRAGS,avgSPOT,avgDEF,avgWIN;
long battles;
double expDAMAGE,expFRAGS,expSPOT,expDEF,expWIN;
double rDAMAGE,rFRAG,rSPOT,rDEF,rWIN;
float rDAMAGEc,rFRAGc,rSPOTc,rDEFc,rWINc;
float wn8;
int tank_id;
avgDAMAGE =2;
return wn8;
}
When I assign the value for the variable avgDAMAGE I get an error in that line saying "expected expression". Can someone help?
Well i solved this error (i guess) what i had to do is to just delete the line a rewrite it..
Thanks for your help guys.

qt select not working with where statement

I'm using qt 4.8 and psql driver to connect to a postgres 9.1 database.
I'm doing a generic library to connect and insert into the database; almost all methods are ready but in the last one, I need to do a select from a table to insert values into another. When I try the select statement it behaves different. According to the code in turn but no one of the tests I made have resulted in a correct solution.
Here's my code:
struct enfriadores enf;
enf.horaE=time(&enf.horaE);
enf.horaS=time(&enf.horaS)+1900;
//base1.insertaEvento(db,enf);
QString consulta = "Select id_evento from eventos where extract(epoch from horae)=:hora_bus";
QDateTime hora_bus(QDateTime::fromTime_t(enf.horaE));
//qDebug()<< enf.horaE;
QSqlQuery query(db);
query.prepare(consulta);
query.bindValue(":hora_bus",hora_bus);
query.exec();
query.first();
while(query.next())
{
int valor = query.value(0).toInt();
qDebug() << valor << endl;
}
The base1.insertaEvento is a call from a class I did to insert data on the table where afterwards I'll need to extract the id. The
qDebug() << enf.horaE;
I put it to know if the time was in the right form before I attached it to the query, which by the way, was correct.
horaE is taken from a struct I have declaed in the previously mentioned class.
When I run the query as it is with the while(query.next()) it runs good but returns no results and if I delete the while loop but still maintain the query.next() compiler returns
QSqlQuery::value: not positioned on a valid record
0
I tried using the query.first() method and the query.setForwardOnly(true) but with same results.
Also if I try the value of hora_bus with qDebug() and replace it directly in the psql console I get a positive match so the problem is not in the way data is inserted or formatted, it's in the way the query is retrieved I believe but do not know how to resolve this
Any ideas?
Thanks
The SQL expression extract(epoch from horae) produces a number of seconds since 1/1/1970 so so that's what should be passed to the parameter :hora_bus.
The QDateTime::fromTime_t(enf.horaE) indicates that enf.horaE has this value, however instead of passing ot to the query, it's passing a QDateTime object whose text representation is probably going to be a string with year,month,etc... that can't be compared to a number of seconds.
So try this instead:
query.bindValue(":hora_bus",enf.horaE);
Also the code shouldn't ignore the boolean return values of prepare() and exec(). You don't want to try looping within results when the execution of the query has failed.
EDIT1:
indeed when passing a QDateTime set to today to a prepared query similar to yours, QSqlQuery::exec() returns false with an SQL error invalid input syntax for type double precision.
EDIT2: it appears QVariant doesn't support being initialized with a long so an explicit cast to a different supported type is necessary. I've chosen qlonglong for a safe larger value:
query.bindValue(":hora_bus",(qlonglong)enf.horaE);
Tested, it worked for me.
http://qt-project.org/doc/qt-4.8/qsqlquery.html#details
At the very end of the documentation it mentions the following:
Warning: You must load the SQL driver and open the connection before a QSqlQuery is created. Also, the connection must remain open while the query exists; otherwise, the behavior of QSqlQuery is undefined.
If the connection to the database is timing out, or one of the variables you are using goes out of scope, you might disconnect early and get undefined results.
You can also check the return values on most of your function calls to see if they were successful or not.
Hope that helps.

WxWidgets using wxString

I'm taking a computer sciences class and we have to make a calculator using a GUI. I have been banging my head into a wall trying to even get input though.
Understand how to use pointers and GetValue(), to take in the input as a wxString but that does me no good, If I can't get the string as a double or integer then I can't perform operations on it.
Does anyone know how to convert wxString to Double? or even int?
Thanks in Advance
For this purpose, there are the two functions ToDouble and ToLong.
For details take a look at the offical documentation:
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtolong
http://docs.wxwidgets.org/stable/wx_wxstring.html#wxstringtodouble
EDIT: Example:
wxTextCtrl ctrl;
// user has entered a number
double number;
if( !ctrl.GetValue().ToDouble( &number ) )
// handle error
else
// continue...
Please note: It will only work if you enter a number. If you enter a term like 2+3 the function should return false. In this case you have to split the string up and interpret all numbers seperately.