Do the names of Qt's objects have to be unique? - qt

Does the QObject::objectName property have to be unique for the whole application? For example, let's say I have button somewhere called "new", then somewhere else I'm going to create a QShortcut also called "new". Is it going to cause a problem to Qt?
I know about properly naming objects (something called "new" is not a good name) but I just want to know whether I need to be extra careful or not.

Object names are not required to be unique. However, there are at least two things I can think of to consider when naming your objects:
QObject::findChild() - A function where you can search for QObjects by name.
Style sheets. If you ever specify a style sheet for a widget by name, it will apply to objects in the hierarchy underneath the widget with that style that have that name.

Other things to consider:
Objects to not require names. If you're not using the names in any meaningful way, you don't have to set them. I normally don't set them for one-off objects like QTimers and such.
If you're using designer to make a .ui file (doesn't sound like you are, but just in case), uic tends to spit out warnings for duplicate names. So if you don't want to see those warnings, keep the names in the .ui file unique (designer tends to enforce this by appending _1, _2, etc to duplicate names).

Related

IPython cell_magic access to cell id

We implemented an IPython extension using the #magics_class (and #line_magic and #cell_magic) annotations. It is working quite well for the most part, with one important limitation. #cell_magic only gets the cell contents as an argument, but we need a way of identifying the actual cell somehow.
I suspect IPython would internally have an identifier for each cell, but this is not passed into the cell magic as far as I can tell.
The reason for needing this is because we want different functionality depending on whether the call is the result of an edit or whether it's a new cell.
Thanks!

Hierarchy of a Java programme?

Is it fair to say that a Java programme is structured as follows ?
PACKAGES contain CLASSES contain OBJECTS contain VARIABLES.
The variables interact with Variables in other Classes through Methods ?
No, not really.
First of you have packages - they can contain other packages or classes.
Each class can contain inner classes, fields (which are instances of classes or native types), static members, etc.
An object contains fields (not variables since some may be final) and methods.
Object instances (final or not) have methods which may have an effect on them or the input or some global state.
Dont try to over-simplify it - it is not very complicated but it is neither thiiiis simple.

Adobe CQ: Make two <cq:include> with same path editable

I have two "cq:include" in same jsp with same path and I need to make both of them editable. But currently only one of them is editable.
If I change anything in one component that shows on second. But the second one itself is not editable. My requirement is to make both the components editable while keeping the include path same.
Code:
<cq:include path ="abc" resourceType="xyz"/>
<cq:include path ="abc" resourceType="xyz"/> # This one is not editable.
Having two components with the same resource type would create only a single node at the given path. Hence, any change you make in one of the component would be reflecting in both of them, as both the components would be reading from the same node.
This is also the reason for not being able to edit the second component. Try providing different paths for different components like shown below.
<cq:include path="abc" resourceType="xyz" />
<cq:include path="abc_0" resourceType="xyz" />
Similar questions have been asked here and here
The way the authoring system works it hooks per location so if you want to have it authored in two different places those two different places should NOT be on the same page. This is just good usability as it can be very confusing.
INSTEAD, I suggest the first one on the page add an attribute to the slingRequest noting that it has been placed on the page and future instances with the same path put a message on the screen saying that it is edited elsewhere. Without knowing more details it's hard to suggest the best usability for this scenario.
Update:
If you MUST do this, here is a work around.
Step 1: define a convention for naming 2 properties. e.g. realTitle (String) and realTitleLastUpdated (date/time). These will be page-level properties, making it easy to access and check them using pageProperties. Though you can do this through a subnode as well but that gets more complicated.
Step 2: For the components that must all be simulateously editable, allow them to create their own nodes. Then, on load in the EDIT environment, check the property realTitle and the lastUpdated time stored in realTitleLastUpdated
If the last edit of your component's title, e.g. jcr:lastModified is newer than realTitleLastUpdated, change the local value of title (e.g. jcr:title) to the value of the realTitle property and update the realTitleLastUpdated time to reflect the time in jcr:lastModified on your component.
If the opposite is true - realTitleLastUpdated is of a time newer than the last modification of the local component, then update the jcr:title of the component and the times to match.
Obviously if the last update times match, do nothing.
It's a bit of a run around, but this will keep everything in sync.
I realized that you may not realize that you probably need to save the state. I believe you can do this (among other ways) using resource.getResourceResolver().adaptTo(Session.class).save()
I've done this before but it's been a while. Let me know if you have issues, I'm working from memory.
Well, if you don't want author to bother about editing both the components, then you should use javascript/jquery and onChange() of one of the component, modify the value of another component as well.

Best way to list files in a QFileSystemModel()?

I'm beginning Qt/pySide programming and am trying to implement a simple QListView with QFileSystemModel as the model. I have this working and in addition have defined a name filter on the model. I'd like to get a list of all files in the QListView (or rather the underlying model).
The following code appears to do this, but is incredibly ugly and cannot possibly be the correct way. Help!
model = myQListView.model()
idx = model.index(model.rootPath())
for i in range(0, model.rowCount(idx)):
child = idx.child(i, idx.column())
print model.fileName(child)
That is the correct way of working. The whole idea of the QAbstractItemModel abstraction is to provide a unified API for accessing arbitrary and possibly dynamic data which happen to fit into a list, table or tree presentations. Because this API has to accomodate everything from a simple dummy list of a few strings to the contents of an address book, including the rich contact details, it is inherently complex. Depending on what you want to achieve, using a one-purpose tool might be better in your specific situation.
By the way, the QFileSystemModel is very dynamic in nature (the directory enumeration happens on a separate thread). You won't get meaningful data until the directoryLoaded signal is emited, you have to wait for it. If you are simply looking for a list of files to use in your code, using Python's native facilities might be easier.

Is Less a single pass compilation process?

Does Less perform one pass over the files or does it do multiple passes?
Mainly, I'm concerned if I include another file that redefines variables/mixins, will the variables/mixins be the original or the override values be used for the generation?
Yes, mixins variables that are declared later in the code override previous code, just like in css if you declare the same class in two places the later ones property values will be the ones to be in effect.

Resources