I'm using Qt 4.5 and im working with a QList<QStringList> which is a list of string list.
Now I want to replace one string inside one stringList but with it seems unusual to type. I have found the following way of doing it and was wondering if it is ok:
QList <QStringList> pDataList;
pDataList[listIndex].replace(QStringIndex, newString);
Now, I'm not worried about the syntax, but I want to know if pDataList's pointers is adjascent in memory so that it is okay to use []. Is there another way to do it?
The issue of pDataList's elements being adjacent in memory is not related to the question of whether it is ok to use operator[].
In general, QList<> does not guarantee that its elements are adjacent in memory, but it does overload operator[] to give you the element you're looking for nonetheless.
The only thing you need to worry about when doing something like this is to make sure that (pDataList.size() < listIndex). otherwise, you'll be indexing elements not in the list, triggering an exception in debug or undefined behavior in release.
Related
I want to remove a property from a node.
Using "removeProperty(NodeRef nodeRef, QName qname)" i can remove it, but i don't know will it cause any problem(like data correption, indexing issue or something ).
Can anyone please help me
The short answer is, no - it won't cause any data corruption or indexing issues. One caveat to this, the data model will not allow you to remove mandatory properties (you'll get an error if you attempt to do this). It will not cause any issues with indexing.
OK so like a lot of us novice codehacks, I've gotten to the point where, through trial and error, I can throw together a relatively fun and reasonably stable game without really understanding WHY a lot of my code works, and I have a poor understanding of pointers and data management. I've tried studying, but since I lack a formal academic background in computer science and have 15 years of experience coding, the introductory stuff is way too easy, and the advanced stuff uses a ton of terminology I don't understand paired with code that I do.
I'm trying to understand why it is that sometimes I can define a new variable, point it at another variable, and then change the pointed data indirectly, and sometimes I can't. Here's an example where it DOES work as I expect:
NSString *myString = [MySingleton sharedMySingleton].singletonString;
myString = #"Hello there!";
[myString retain];
By changing the locally defined "myString" i can cause changes to the singleton string.
Here's an example where it DOESN'T work as I expect:
HUDLayer *windowBox = shopWindowBox;
[windowBox addChild: shop];
[windowBox retain];
In this case, HUDLayer is just an essentially blank file, and "shop" is a menu containing my store, and "shopWindowBox" is an instance of HUDLayer. If I call the code with [shopWindowBox addChild: shop], it works, but as soon as I try to define a new HUDLayer and point it, it doesn't work.
I understand that I'm doing a very fundamentally different operation, in one case I'm changing the contents of a string, and in another case I'm adding a child. The conclusion I've come to is "you can't add children to a pointed data", but am I really understanding this correctly, an if so why not?
I found a code error in a different block that was setting its visibility to FALSE.
I was attempting to make the code more plug-and-play by changing "shopWindowBox", "unitWindowBox", and "unlockablesWindowBox" all to be locally defined variable with windowBox, but my "hideUnitWindowBox" and "hideUnlockablesWindowBox" functions were setting the visibility of my shop window to FALSE after populating it.
I guess pointers not only work as I expected, they work BETTER than I expected... I stupidly merged 4 different windows into a single window using pointers.
EDIT:
I went back and provided a long explanation of each of the below.... Then I started thinking. I think my issue was the division element (getUnitDivisionFactor()) was not observable. I changed this to an observable data type and it all started working. So rather than delete this "stupid question" I will leave it around. Perhaps this will help someone else.
I am using JFXtras 2. There is an "LCD" widget that has a valueProperty binding. It is a double binding. I am binding like this... Which is not working...
xLcd.valueProperty().bind(TinygDriver.getInstance().m.getAxisByName("x").getMachinePositionSimple().subtract(TinygDriver.getInstance().m.getAxisByName("x").getOffset()).divide(tg.m.getUnitDivisionFactor()));
The problem I really need to do the subtraction first..
(getMachinePositionSimple - getOffset()) / getUnitDivisionFactor()
However I am a bit stumped on how to do this in a single binding setup. I think number bindings might be the way to go. However, not quite sure how to set that up right?
Any help would be great.
Riley
The getUnitDivisonFactor() was returning a regular double data type. I changed this to a SimpleDoubleProperty and everything just started working.. See
xLcd.valueProperty().bind(TinygDriver.getInstance().m.getAxisByName("x").getMachinePositionSimple().subtract(tg.m.getAxisByName("x").getOffset()).divide(tg.m.gcodeUnitDivision));
Are the any GIL-less LLVM-based languages, targeted mainly for JIT-execution which allows to reload PART of the code on the fly?
Like re-compile 1 class, and reload it without stopping the whole program.
Anyone tryed that?
Any chance on doing that with clang (surely, with great deal of developers caution, restriction and manual state handling)?
I think that this is a dynamite idea, and a feature that I would love to have! Have you given any thought to how you would like to interface with the feature?
obj1 = Foo()
compiler.Recompile(Foo, '/some/path/myapp/newsrc/foo.blah');
obj2 = Foo()
// Would this be True?
type(obj1) == type(obj2)
I assume that you expect existing instances to remain unchanged by the recompile?
This seems like it would be easier with functions, as long as they kept the same prototype, but doing it with classes seems like it would get messy.
Also, what to do about threading?
Thread.start(wait 1; bar();); // bar is a function
compiler.Recompile(bar, '/some/path/myapp/newsrc/bar.blah');
Lets say that in our thread we start calling "bar" during the recompile. Does the call block until the recompile is done and then call the new function? Does the old function still exist until the compile is complete? What if we have a function pointer, after the recompile, where does it point? To the original function or to the new one?
Does anyone have any thoughts on how this could be implemented in a strait forward way?
Hmm, can't think of anything off the top of my head. The only major product I can think of is JRebel, but that's for Java.
Apparently, it does not exist yet.
What it says on the tin: I have an XMLList, and I want to find where in it a particular XML item falls. First index is good enough for my purposes.
Note that I have no problem writing a function to do this by hand... but I was hoping that the API has something buried somewhere that'll do it for me. I didn't see it, though.
Just loop through the xmllist until you find one that matches, then return the index in your loop (for loop with an index).
Without a code example it's a bit difficult to know what you're trying to do exactly, but maybe XML.childIndex() could the solution?