I'm beginning with Wt, and after taking the basics of ORM module, I'm trying to show the results of a table (TableTags) with no success.
I have defined table TableTag as:
class TableTag
{
public:
static const unsigned int tableVersion = 1;
std::string name;
//Wt::Dbo::collection< Wt::Dbo::ptr<TablePost> > tablePosts;
TableTag();
~TableTag();
static void initTableRecords(Wt::Dbo::Session &_session);
template<class Action>
void persist(Action &_action)
{
Wt::Dbo::field(_action, name, "Name");
//Wt::Dbo::hasMany(_action, tablePosts, Wt::Dbo::ManyToMany, "Post");
}
};
typedef Wt::Dbo::collection< Wt::Dbo::ptr<TableTag> > TableTags;
and I'm begginning with a code similar to:
DDBBApp::setDDBBBackendAndSession(ddbbBackend_,ddbbSession_);
ddbbSession_.mapClass<TableTag>("TableTag");
{
Wt::Dbo::Transaction transaction(ddbbSession_);
Wt::Dbo::QueryModel<TableTag> * qmTags = new Wt::Dbo::QueryModel<TableTag>();
TableTags tags = ddbbSession_.find<TableTag>();
Wt::Dbo::Query<TableTag> qTag(ddbbSession_.find<TableTag>());
qmTags->setQuery(qTag);
WTableView * wtv = new WTableView();
wtv->setModel(qmTags);
}
but compiler complains with this error (VS2013, translated to English):
DDBBApp.cpp(54): error C2664:
'Wt::Dbo::Query::Query(Wt::Dbo::Session
&,const std::string &,const std::string &)' : argument 1 cannot be converted from 'Wt::Dbo::Query' to 'const
Wt::Dbo::Query &'
I've tried several constructors, variable types, etc... I know the point is close to this:
Wt::Dbo::QueryModel<TableTag> * qmTags = new Wt::Dbo::QueryModel<TableTag>();
Wt::Dbo::Query< Wt::Dbo::ptr<TableTag> > q1 = ddbbSession_.find<TableTag>();
qmTags->setQuery(qTag); //Error here
Wt::Dbo::Query<TableTag> q2 = ddbbSession_.find<TableTag>(); //Error here
qmTags->setQuery(q2);
But I'm not able to deal with this, I think the right way is 2nd one, according to the docu and snippets I've googled.
Can someone post a simple example so I can clarify how Wt works with this?
Wy the wall, I'm using Wt 3.3.3 under Win 8.1 + VS 2013.
Finally I figured it ^_^ thanks to: Not getting headers on WTableView with QueryModel
The rigth piece of code is as follows:
Wt::Dbo::QueryModel< Wt::Dbo::ptr<TableTag> > * qmTags1 = new Wt::Dbo::QueryModel< Wt::Dbo::ptr<TableTag> >();
qmTags1->setQuery(ddbbSession_.find<TableTag>());
qmTags1->addAllFieldsAsColumns();
WTableView * wtv1 = new WTableView();
wtv1->setModel(qmTags1);
this->root()->addWidget(wtv1);
Note: don't forget to use QueryModel->setQuery()!!
Related
I have been trying to reproduce something even simpler than the C++ sample in: https://github.com/google/flatbuffers/blob/master/samples/sample_binary.cpp
But I am getting some compile errors in VS2017 on the lines
//auto pos = compare->pos;
//auto two = compare->deviceType;
//auto desc = compare->description;
If I comment them out, it compiles and runs. If not, then I get the following errors:
Severity Code Description Project File Line Suppression State
Error C3867 'PNT::PseudoGPS::pos': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 50
Error C3867 'PNT::PseudoGPS::deviceType': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 51
Error C3867 'PNT::PseudoGPS::description': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 52
Here is the definition of my FBS object:
// Example IDL file for the PNT Schema
namespace PNT;
enum DeviceType:byte { IMU, VAN, GPS, MAGNAV, SOOP }
struct Vec3 {
x:float;
y:float;
z:float;
}
table PseudoGPS {
pos:Vec3;
deviceType:DeviceType = GPS;
description: string;
}
root_type PseudoGPS;
And here is the code that creates the FB object and then tries to access things (I am just exploring at this point, the code is not done).
flatbuffers::FlatBufferBuilder builder(1024);
auto position = PNT::Vec3(4.0, 5.0, 6.0);
auto description = builder.CreateString("Magnetic Postion");
auto msg = PNT::CreatePseudoGPS(builder, &position, PNT::DeviceType_MAGNAV, description);
builder.Finish(msg);
uint8_t *buf = builder.GetBufferPointer();
int size = builder.GetSize();
auto compare = PNT::GetPseudoGPS(buf);
auto pos = compare->pos;
auto two = compare->deviceType;
auto desc = compare->description;
compare->pos refers to an accessor function, try appending ()
I am trying to create an array of boolean functions, this is currently where I am at.
typedef bool(*fn)(DIYObject*, DIYObject*);
static fn collisionfunctionArray[] =
{
DIY::sphere2Sphere
};
bool DIY::sphere2Sphere(DIYObject* obj1, DIYObject* obj2)
{
DIYSphere *sphere1 = dynamic_cast<DIYSphere*>(obj1);
DIYSphere *sphere2 = dynamic_cast<DIYSphere*>(obj2);
if (sphere1 != NULL && sphere2 != NULL)
{
float X;
X= sphere1->m_position.x - sphere2->m_position.x;
X = X *X;
float Y;
Y = sphere1->m_position.y - sphere2->m_position.y;
Y = Y *Y;
float distance;
distance = sqrt(X + Y);
float distanceCompare;
distanceCompare = sphere1->m_radius + sphere2->m_radius;
if (distance < distanceCompare)
{
sphere1->m_velocity = vec3(0,0,0);
sphere2->m_velocity = vec3(0, 0, 0);
}
}
return false;
}
So at the moment I am only trying to insert one function into the array but I am receiving the following error
Error 2 error C2440: 'initializing' : cannot convert from 'bool (__thiscall DIY::* )(DIYObject *,DIYObject *)' to 'fn'
I think I'm taking in the same arguments so I don't really understand what the issue is here. Thanks
The problem is that sphere2Sphere is a member function of the DIY class and needs an object to put in its this pointer.
As your sphere2Sphere function doesn't use the this pointer (I think), you can make it static, which means it will then match the fn type (as the compiler will know it doesn't need the (hidden) this parameter).
Note: The static keyword goes in the method declaration in your class definition, which you haven't shown here.
I'm having a hard time trying to get an app to compile in Visual Studio 2013. I've solved a good amount of errors but I can't find a solution for the last one.
here it is:
void Application::setupRenderSystem() {
mState->dumpValues();
String val = mState->getStringValue("renderSystem");
RenderSystemList *renderSystems = mRoot->getAvailableRenderers();
RenderSystemList::iterator r_it;
bool renderSystemFound = false;
for (r_it = renderSystems->begin(); r_it != renderSystems->end(); r_it++) {
RenderSystem *tmp = *r_it;
std::string rName(tmp->getName());
// returns -1 if string not found
if ((int)rName.find(val) >= 0) {
mRoot->setRenderSystem(*r_it);
renderSystemFound = true;
break;
}
}
if (!renderSystemFound) {
OGRE_EXCEPT(0, "Specified render system (" + val + ") not found, exiting...", "Application")
}
}
Visual Studio indicates that the line RenderSystemList *renderSystems = mRoot->getAvailableRenderers(); is the problem, especially mRoot
Here is the error I get:
error C2440: 'initializing' : cannot convert from 'const Ogre::RenderSystemList' to 'Ogre::RenderSystemList *'
The getAvailableRenderers method doesn't return a pointer to a RenderSystemList. You'd want to have the value stored in a reference to a RenderSystemList:
RenderSystemList const& renderSystems = mRoot->getAvailableRenderers();
The Ogre API says:
const RenderSystemList & getAvailableRenderers (void)
So it returns a const reference and not a pointer.
Modify your code like this
const RenderSystemList &renderSystems = mRoot->getAvailableRenderers();
I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;
The segmentation fault is caused in the scanner code.
The Problem:
Using GDB to backtrack reveals that the problem is caused with the declaration of the FieldInfo Pointer named field_info (where FieldInfo is a struct) in the condition: if (tell_me).
Please note the the following code is a part of a large file, so if there are some things whose declaration is not here, you can probably assume that they would have been defined in the program somewhere else and not shown here.
The sample code:
Some_function(some_arguments) {
// Did something.
if (flag_1) {
list<const FieldInfo *> prefix_stack;
const FieldInfo def_pfx(NON_BOOLEAN, default_prefix);
{
const FieldInfo * default_field_info = &def_pfx;
if (default_prefix.empty()) {
map<string, FieldInfo>::const_iterator f = field_map.find("");
if (f != field_map.end()) default_field_info = &(f->second);
}
// We always have the current prefix on the top of the stack.
prefix_stack.push_back(default_field_info);
}
// Did something.
for (<some conditions>) {
bool tell_me = false;
// Did something.
if (tell_me) {
const FieldInfo pos_prefix(NON_BOOLEAN, pos);
const FieldInfo * field_info = &pos_prefix;
Term * term_obj = new Term(&state, term_lowercase, field_info,
term, stem_term, term_pos++);
Parse(pParser, token, term_obj, &state);
} else {
const FieldInfo * field_info = prefix_stack.back();
Term * term_obj = new Term(&state, term_lowercase, field_info,
term, stem_term, term_pos++);
Parse(pParser, token, term_obj, &state);
}
// Did something.
}
}
// Did something.
}
And the definition of FieldInfo is:
struct FieldInfo {
/// The type of this field.
filter_type type;
/// Field prefix strings.
list<string> prefixes;
/// Field processors struct already defined earlier.
list<FieldProcessor*> procs;
FieldInfo(filter_type type_, const string & prefix)
: type(type_)
{
prefixes.push_back(prefix);
}
FieldInfo(filter_type type_, FieldProcessor *proc)
: type(type_)
{
procs.push_back(proc);
}
};
Analysis:
Parse is a method that calls the Parser.
GDB reveals that the problem (segmentation fault) is caused when the Parser tries to process the field_info by iterating over the field_info->prefixes.
EDIT:
Here is the code of the function where the segmentation fault occurs (I have added some cout for the debugging purposes). The problem comes is in the while (++piter != prefixes.end()) part of code:
Query get_query() const
{
const list<string> & prefixes = field_info->prefixes;
if (prefixes.empty()) {
assert(!field_info->procs.empty());
return (**field_info->procs.begin())(name);
}
list<string>::const_iterator piter = prefixes.begin();
Query q(make_term(*piter), 1, pos);
while (++piter != prefixes.end()) {
string check3 = make_term(*piter);
Query q2(check3, 1, pos);
q = Query(Query::OP_OR, q, q2);
}
return q;
}
NOTE:
I am working on some-one else's working code.
I have added the if(flag_1) part of code, and rest everything else was there already.
This part looks suspicious:
const FieldInfo pos_prefix(NON_BOOLEAN, pos);
const FieldInfo * field_info = &pos_prefix;
Term * term_obj = new Term(&state, term_lowercase, field_info,
term, stem_term, term_pos++);
You are using the address of the local variable pos_prefix to initialize term_obj. You have to make absolutely sure that this address is never accessed after pos_prefix has gone out of scope, because then the address will be invalid.
You are having an awful lot of raw pointers in your code. This is not good practice in modern C++. Consider using plain objects, references or smart-pointers.