this is my first question and I'm quite struggeling. I'm using Qt for creating a software for excentric viewing. A group of students did this project before, so I got pre-made code to work with.
My problem is the following one:
I am not coding the usual way, I use the QDesigner. I have a Scroll Area where I want to fit some QGroupBoxes inside. There is a general box named "Properties" which holds some other boxes with a vertical layout.
Now one of the boxes is called "symbolgen" and is using a custom class, called "SymbolGen". The class is defined as followed:
class SymbolGen : public QGroupBox
Now what I like to do is to extract alle boxes from the "Properties" box. That means: I want to replace the Group "Properties" by a label "Properties" and underneath with the smaller boxes. Now what Qt says to me is the following:
Fehler: C2664: "SymbolGen::SymbolGen(const SymbolGen &)" : Konvertierung von Argument 1 von "QWidget *" in "QGroupBox *" nicht m”glich
Yes, I am German, in English:
Error: C2664: "SymbolGen::SymbolGen(const SymbolGen &)" : Conversion from argument 1 of "QWidget *" to "QGroupBox *" not possible.
What I see here is, that this specific Group Box "symbolgen" (holds some important variables in the class) needs another group box around. So how can I get this box separated without error?
Thanks for your help!
edit://Line that causes this error:
symbolgen = new SymbolGen(scrollAreaWidgetContents_2);
This one is found at "ui_admin.h".
edit://Definition of "scrollAreaWidgetContents_2" from "ui_admin.h":
scrollAreaWidgetContents_2 = new QWidget();
scrollAreaWidgetContents_2->setObjectName(QStringLiteral("scrollAreaWidgetContents_2"));
scrollAreaWidgetContents_2->setGeometry(QRect(0, 0, 503, 851));
edit://SymbolGen::SymbolGen(const SymbolGen &):
SymbolGen::SymbolGen(QGroupBox *g) : QGroupBox(g)
{
srand (time(NULL));
//Wörterquelle lesen
std::ifstream f("source/ngerman.txt");
std::string l;
if(f.is_open())
{
while(f.good())
{
getline(f,l);
words.push_back(l);
//if( words.size() > 10000 ) break;
}
}
f.close();
//Satzquelle lesen
std::ifstream fs("source/sentences.txt");
//std::string l;
if(fs.is_open())
{
while(fs.good())
{
getline(fs,l);
phrase.push_back(l);
//if( words.size() > 10000 ) break;
}
}
fs.close();
}
It seems g is just the parent widget, that is just passed down to the constructor of QGroupBox, and which should be of type QWidget* instead of QGroupBox*.
You could change that in the declaration, as the QGroupBox constructor expects a QWidget* anyway. There may be a reason this was done this way, so the class may rely on the fact that the parent is a group box. Still, I would try to change it and see what happens.
Related
I am trying to pull the Enum chosen from a dialog and assign the label to a table's column.
For example: Dialog opens and allows you to choose from:
Surface
OutOfSpec
Other
These are 0,1,2 respectively.
The user chooses OutOfSpec (the label for this is Out Of Spec), I want to put this enum's Name, or the label, into a table. The column I'm inserting into is set to be a str.
Here's the code I've tried, without success:
SysDictEnum dictEnum = new SysDictEnum(enumNum(SDILF_ScrapReasons));
reason = dialog.addField(enumStr(SDILF_ScrapReasons),"Scrap Reason");
dialog.run();
if (!dialog.closedOk())
{
info(reason.value());
return;
}
ttsBegin;
// For now, this will strip off the order ID from the summary fields.
// No longer removing the Order ID
batchAttr = PdsBatchAttributes::find(itemId, invDim.inventBatchId, "OrderId");
orders = SDILF_BreakdownOrders::find(batchAttr.PdsBatchAttribValue, true);
if (orders)
{
orders.BoxProduced -= 1;
orders.update();
}
// Adding a batch attribute that will include the reason for scrapping
select forUpdate batchAttr;
batchAttr.PdsBatchAttribId = "ScrapReason";
//batchAttr.PdsBatchAttribValue = any2str(dictEnum.index2Value(reason.value()));
batchAttr.PdsBatchAttribValue = enum2str(reason.value());
batchAttr.InventBatchId = invDim.inventBatchId;
batchAttr.ItemId = itemId;
batchAttr.insert();
Obviously this is not the whole code, but it should be enough to give the issue that I'm trying to solve.
I'm sure there is a way to get the int value and use that to assign the label, I've just not been able to figure it out yet.
EDIT
To add some more information about what I am trying to accomplish. We make our finished goods, sometimes they are out of spec or damaged when this happens we then have to scrap that finished good. When we do this we want to keep track of why it is being scrapped, but we don't want just a bunch of random reasons. I used an enum to limit the reasons. When the operator clicks the button to scrap something they will get a dialog screen pop-up that allows them to select a reason for scrapping. The code will then, eventually, put that assigned reason on that finished items batch attributes so that we can track it later in a report and have a list of all the finished goods that were scrapped and why they were scrapped.
I'm not entirely sure of your question, but I think you're just missing one of the index2[...] calls or you're not getting the return value from your dialog correctly. Just create the below as a new job, run it, make a selection of Open Order and click ok.
I don't know the difference between index2Label and index2Name.
static void Job67(Args _args)
{
Dialog dialog = new dialog();
SysDictEnum dictEnum = new SysDictEnum(enumNum(SalesStatus));
DialogField reason;
SalesStatus salesStatusUserSelection;
str label, name, symbol;
int value;
reason = dialog.addField(enumStr(SalesStatus), "SalesStatus");
dialog.run();
if (dialog.closedOk())
{
salesStatusUserSelection = reason.value();
// Label
label = dictEnum.index2Label(salesStatusUserSelection);
// Name
name = dictEnum.index2Name(salesStatusUserSelection);
// Symbol
symbol = dictEnum.index2Symbol(salesStatusUserSelection);
// Value
value = dictEnum.index2Value(salesStatusUserSelection);
info(strFmt("Label: %1; Name: %2; Symbol: %3; Value: %4", label, name, symbol, value));
}
}
I want to update my code from old style casting to new style one. I have some problems with understanding the different type of casts.
1 case
if (((QDataItem*)(*it))->GetType()==QDataItem::AudioTrack){
Here I have a class "QDataItem". This contain an enum of track types, like AudioTrack. Basing on a QTreeWidget I iterate through the QTreeWidget items. Each Item represents a QDataItem. Now with new casting I want to do:
if ((static_cast<QDataItem*>(*it))->GetType()==QDataItem::AudioTrack){
Is this there right way to do?
2 case
In old style I have a twice casting
QAudioTrackItem *audio_track = (QAudioTrackItem*)(QDataItem*)(*it);
QAudioTrackItem is like QDataItem a class. I want to do here:
QAudioTrackItem *audio_track = reinterpret_cast<QAudioTrackItem*>(*it)
But I am not sure that this is correct in case of the missing QDataItem cast.
Is my result ok or do I have a bug?
Is this there right way to do?
Yes, (QDataItem*)(*it) and static_cast<QDataItem*>(*it) should be identical with your code.
But if your classes have such inheritance structure:
class QDataItem : QObject {};
class QAudioTrackItem : QDataItem {};
you should really consider using qobject_cast<>() instead:
if (auto item = qobject_cast<QAudioTrackItem *>(*it)) {
....
}
Is my result ok or do I have a bug?
Maybe, it depends on how your inheritance structure look like.
If they inherit just like my example above, it's totally OK to use reinterpret_cast<>() to convert any pointers between QObject, QDataItem and QAudioTrackItem.
But if your classes have multiple inheritance:
class QDataItem {};
class QAudioTrackItem : QObject, QDataItem {};
reinterpret_cast could kick your ass badly:
auto item = new QAudioTrackItem;
auto p1 = reinterpret_cast<QObject *>(item); // OK
auto p2 = reinterpret_cast<QAudioTrackItem *>(p1); // OK
auto p3 = reinterpret_cast<QDataItem *>(item); // Undefined Behavior
auto p4 = reinterpret_cast<QDataItem *>(p1); // Undefined Behavior
i have this code that gives me run time error in the line :
body->CreateFixture(&boxDef)
im using cocos2d-x 2.1.5 with box2d 2.2.1 in windows
CCSprite *sprite = CCSprite::create(imageName.c_str());
this->addChild(sprite,1);
b2BodyDef bodyDef;
bodyDef.type = isStatic?b2_staticBody:b2_dynamicBody;
bodyDef.position.Set((position.x+sprite->getContentSize().width/2.0f)/PTM_RATIO,
(position.y+sprite->getContentSize().height/2.0f)/PTM_RATIO);
bodyDef.angle = CC_DEGREES_TO_RADIANS(rotation);
bodyDef.userData = sprite;
b2Body *body = world->CreateBody(&bodyDef);
b2FixtureDef boxDef;
if (isCircle)
{
b2CircleShape circle;
circle.m_radius = sprite->getContentSize().width/2.0f/PTM_RATIO;
boxDef.shape = &circle;
}
else
{
b2PolygonShape box;
box.SetAsBox(sprite->getContentSize().width/2.0f/PTM_RATIO, sprite->getContentSize().height/2.0f/PTM_RATIO);
boxDef.shape = &box;
}
if (isEnemy)
{
boxDef.userData = (void*)1;
enemies->insert(body);
}
boxDef.density = 0.5f;
body->CreateFixture(&boxDef) //<-- HERE IS THE RUN TIME ERROR
;
when i debug the box2d code im getting to b2Fixture.cpp
in the method :
void b2Fixture::Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def)
in the line :
m_shape = def->shape->Clone(allocator);
getting the runtime error :
R6025 pure virtual function call
Tricky one. I ran into this myself a couple times. It has to do with variable scope.
The boxDef.shape is the problem. You create the shapes as local variables in the if/else blocks and then assign them to boxDef. As soon as execution leaves the if/else block scope those local variables will be garbage. The boxDef.shape now points to freed memory.
The solution is to keep the shape variables in scope by moving the circle and box shape declarations before the if/else block.
I have A class Named “Student” !
I have a Q Vector From Student class
Now I want To show the form of the 2nd Student in my vector !
but when it shows It is empty , it doesn’t show things the thing in the Ui
What should I do ?! Douse it even can happen ? Or it is not possible in Qt
This is My QVector:
StHead = new QVector <Student> ;
This is My Code :
void MainWindow::StudentSignIn (QString User,QString Pass)
{
///////Sign in things !
int index = StudentSearch(User);
Student* at = StHead->data();
if (at[index].GetPass() == Pass)
emit Hide_StuLog();
at[index].show();
}
I am seeing a strange issue in flex. I need to reset all text input fields to 0 once the
user submits the values to be calculated. In the method
private function calculate():void {
resetToZero();
var num:Number = parseFloat(s21.text);
}
private function resetToZero():void {
//multiple if statements.... existing here..
if(s2l.text.length ==0);
{
Alert.show("length is:" + s2l.text.length);
s2l.text="0";
}
}
When I am running the program I am getting the alert - length is 1. How is that it when length is 1 it is entering the if statement?. The behavior is really confusing and need some light on this. Is there any other way to achieve the above functionality?
Its because of IF statement, which is terminated
if(s2l.text.length ==0);
Remove ; from end as
if(s2l.text.length==0)
Hopes that helps