The old QWidget::event() return value question? - qt

Long years past a user asked this question on the Qt centre forum and it was left unanswered. It is still relevant, in particular in relation to QWheelEvent. In my experience, the QWheelEvent must be either accept()ed or ignore()d by an event handler, but mouse events can return true and it counts as an accept()? What have you learned in relation to the QEvent::event() return value? Obviously, a returned true does not always count as accept() and the documentation is vague, at best.

Related

Making the keyboard momentarily unresponsive in order to clean an M1 MacBook [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 months ago.
Improve this question
I have been trying to find a way to clean the keyboard and body of my M1 MacBook Air. I used to just turn off my laptop, use a clean cloth to remove dust and fingerprints, and then turn it on. But this laptop cannot be disturbed at all without turning on: a key press, opening the lid, touching the trackpad, anything causes it to turn on. This feature (which, along with the impossibility to disable the turn-on sound, kinda bothers me) cannot be turned off, unlike with Intel MacBooks. I don't like to press keys and touch the keyboard with the computer being responsive, so I was wondering:
Is there a way to make the keyboard momentarily unresponsive? Maybe a Hammerspoon script?
I know this might seem like a silly question, but I would like to be able to handle my computer knowing I'm not gonna press a random key combination which is going to need undoing later. I think Apple should implement a "cleaning mode" where the computer is unresponsive so that one can clean the body of the computer every once in a while.
Thanks!
You need to setup an event tap for the keyboard. You can tap into a variety of events, for example the key down event. Whenever that event is triggered a callback function is executed which is passed the event data (e). Just return true if you want to block the event. That should disable your keyboard.
You can extract the key code and flags (ctrl, shift, option...) from the event. This will allow you to program a shortcut to stop the event tap and make your keyboard functionally again.
For example:
local events = hs.eventtap.event.types
keyboardTracker = hs.eventtap.new({ events.keyDown }, function (e)
local keyCode = e:getKeyCode()
local flags = e:getFlags()
if flags.ctrl and keyCode == hs.keycodes.map.f then
return false
end
return true
end)
keyboardTracker:start()
Be careful, if an unhandled error is thrown from within the callback function you effective disable your keyboard.
Tapping into mouse events is similar.
https://www.hammerspoon.org/docs/hs.eventtap.html
https://www.hammerspoon.org/docs/hs.keycodes.html

Force responses to be from a specific custom slot, repeatedly

I'm attempting to write a "trivia quiz" skill, like many others that already exist, but I would like the user to be able to give actual answers rather than "a/b/c" or "1/2/3". So the conversation will go like this:
Alexa: Which planet is closest to the Sun: Mercury or Venus?
User: Mercury
Alexa: That's correct! You have one point. Which company makes the Corvette, Cadillac or Chevrolet?
User: Chevrolet
Alexa: That's right! You have two points. What were George Washington's false teeth made from? Wood or ivory?
...etc...
Since each question has its own set of answers, I'm happy to create one custom slot type per question, so I'd have a LIST_Q1_ANSWERS slot of ["Mercury", "Venus"] and a LIST_Q2_ANSWERS slot of ["Cadillac", "Chevrolet"], and that's all fine. However, I do not know how to tell my skill that answers should come from this particular custom slot only.
I can of course create a specific Intent for each question, so I create Q1Intent, I start a Dialog, and I Elicit my Q1Intent. However, this doesn't work out, because in my response to their filling in the required LIST_Q1_ANSWERS slot, I have to say "correct" and also ask the next question, which means that I have to Elicit the Q2Intent... and that's not allowed; I'd have to end the Dialog first, and then start a new one. (So the conversation would go "Which planet...?" "Mercury" "Correct! Do you want the next question?" "Yes" "OK. Which company..." and that's no good.)
I may be over-complicating things here. Perhaps there's an easier way to model the voice interface that I want. I can of course define all the different answers in one big custom slot, and then just have one single AnswerIntent, but then people can answer Chevrolet to the planets question and that's silly. (I know that I have to cope with any answers to a question, not just the ones in the slot, but I'd like to bias the question towards choosing answers from the slot; that's what slots are for.)
So, how should I be doing this? Dialogs won't work, I don't think.
That is a very reasonable request, IMO, but it is still not possible with Alexa. With some other bot/AI platforms you can specify a context that causes it to try to match the user response against a subset of your skills intents (usually just 1, I would think).
Here is a popular Alexa feature request that gets at the same point:
Allow temporarily disabling intents/utterances based on application state
https://forums.developer.amazon.com/content/idea/40045/allow-temporarily-disabling-intentsutterances-base.html
Yes, I believe that you can do exactly what you want. I did something similar in my "Who's On First?" baseball skit skill.
There are probably many other ways to accomplish this also, but I took the following approach:
Create an intent for each user response. For example, in the above example you stated, "mercury" and "chevrolet" would each be intents.
Pass information forward in the session object. A database could be used, but the session works well in this case. This information will allow your intent handlers to identify the question that was asked. This isn't really necessary if every answer is unique, but it allows multiple questions to have the same answer. For example, maybe the answer "mercury" is an answer to both questions "name a planet" as well as "name a liquid metal".
Since there will be more possible incorrect answers than correct answers, it might make sense to use slots for the incorrect answers. Alternatively, you might just handle unmatched intents as incorrect answers, and use the question ID passed in the session to identify which question was incorrect.
You can put together the response string programmatically. So if the answer is correct, prepend "Correct, the next question is " to the beginning of the next question your skill says.
I hope this gives you an idea for how to proceed. A lot is possible with Alexa. We just need to get creative sometimes.

Dont know how to solve a maybe infinitfe loop (Tree) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have a problem.
I have a element and another list of elements, which are connected to the first one in some way.
i want to check, which elements of the list are children of the first. Save the result in an array. Then i will pick the first child and look for his children. save that and so on and on and on.
The problem is, i dont know the exact number of relations. so i could have many many loops and searches.
do i need to program every single loop and array (to save to) or is there a better way?
EDIT:
Iam talking about DB tables. I have two tables. I want to check the children (data in table2) for every element in table1. So i start with a Loop in table1. Elements in Table 1 and table2 are connected with coordinates xy. so iam searching for all elements in table2 where table1_element1.xy == table2.xy. As result there could be n children. Now i want to save them and start for those children a new loop to find for every child his children based on the coordinates. save that new result an so on and on.
More clear?
Thank you.
this problem can be easily solved with the help of recursion.
In this case your termination condition will be when any node don't have any relation in the list or when you reach the end of the list where you are storing the children.
Thanks
While the question is a little vague, rather than programming every individual loop, a more elegant way of writing this would be through recursion. You would set your break condition to be when you find a child (if I'm understanding the problem correctly) with no relations.
As for the storage issue, it sounds like you may want to use some form of a Topology data structure where each node would hold a list of all nodes connected to it through your relation.
Hope this helps.

Specific to the world of programming, what does "Turtles all the way down" mean? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I hear this phrase often and do not fully understand it's meaning. What does it mean? And if possible, is there an example?
thank you!
One use of this expression refers to a style of programming where there is a very deep call stack. You might see a method called Grobble and wonder what it does, so you open up the definition and see this:
class FooHandler
{
void Grobble(Foo foo)
{
foo.Grobble();
}
}
So then you look at Foo.Grobble:
class Foo
{
FooImpl _fooImpl;
void Grobble()
{
_fooImpl.Grobble();
}
}
That takes you too FooImpl which looks like this:
class FooImpl
{
void Grobble()
{
this.Grobble(false);
}
// etc...
}
After going deeper and deeper into the code, still unable to see the end, you are allowed to frustratedly exclaim "It's turtles all the way down!"
The reference is to the metaphor of the Earth being on the back of a turtle. What is the turtle standing on? Another turtle... etc.
This usually refers to self-hosting programming languages, where the interpreter or compiler is written in the same language that is being interpreted/compiled. It can also refer to the libraries for the language being written in the language itself.
Smalltalk and Lisp are well known for this kind of thing.
Turtles all the way down is a phrase sometimes used to refer to infinite recursion. For example, what is the least integer? There isn't one. -2 is less than -1, -3 is less than -2 and so on. There is no bottom. The original source of the quote was an answer to the question of "If the world is on the back of a turtle, what does the turtle stand on?". Anyway, it doesn't have any programming specific meaning that I know of.
It is sometimes used to refer to 'pure' object oriented (or functional) languages. In a.o. java, c#, c++, Objective c and Delphi, there are native types (int) that don't behave like objects. The illusion is maintained much better in Smalltalk.

Changes to the user story after the sprint has started [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
What types changes/additions/further clarifications do you think are ok to make to a user story?
what changes/additions/further clarifications do you think are not ok to have happen to the user story?
What types changes/additions/further
clarifications do you think are ok to
make to a user story (after a sprint has started)?
Any that the Product Owner asks for and for the Scrum team still to be comfortable to maintain their commitment to completing all user stories commited to in the sprint.
what changes/additions/further
clarifications do you think are not ok
to have happen to the user story (after a sprint has started)?
Any that the Product Owner asks for and make the Scrum team not comfortable to maintain their commitment to completing all user stories commited to in the sprint.
I think this all depends on the team negotiating with the product owner. In a way, ANY changes to a user story which affect the implementation of the story are not okay.
What the team committed to was the user story as it was specified during sprint planning. Any changes introduced later were not part of the commitment, so the Product Owner (assuming that this is where the changes are coming from) should be aware that any requirement changes need to be signed off by the team.
Then again, this is a very restrictive way of handling this.
For a more real-world answer, I'd say that any changes to the user story need to be brought up to the team and negotiated. The team should be able to estimate the extra time needed to implement the changes and based on this commit to the changed user story or not. If these are little changes it's likely that you can just add the workload to the running sprint without any risks. If it's more effort, come up with a solution that doesn't put the sprint at risk and is agreed upon by the team and product owner. These could be:
Leave out another user story or reduce the scope of another user story.
Try to fit everything in but have a list of optional tasks that you can leave out if the time runs out.
Add resources to the team. Let the sprint run a few days longer.
Write a new user story for the changes and prioritise it so that it gets into the next sprint.
Drop the changed user story for this sprint, rewrite the user story and do it in the next sprint.
Even if the changed requirements pop up because the original requirements proved to be "wrong" in some way, I still think that what the team committed to is what counts. So in the case that the Product Owner decides that the user story as is has no value and needs to be changed, this is not a valid reason to bring all the changed requirements into the sprint. If the effort to apply the changes would put the rest of the sprint at the risk of failing, the better option would be to drop the changed story for this sprint and bring it up again with the changes during the next sprint planning.
The point of a user story is to define a feature that's valuable to the customer. If any aspect of that definition changes, you'd better change the story.
On the other hand, your story point estimates were based on the old story and old acceptance criteria - if changes to a user story dramatically increase the time it takes to complete it, you'll have to split the story and move part of it (or another lower-priority story) into another sprint.
It also depends how close you are to the end of the sprint - if tomorrow's the last day of the sprint, just make a new story to express the changes and add the new story to the next iteration (or the one after that, depending on its urgency).
As I recently referenced in response to another stack overflow question, I think Martin Fowler's blog post on Conversational Stories is a good one for answering questions about user stories.
Clarifications should always be welcome as part of the conversation. Changes that do not change the overall story should be permitted if the team feels it has time to complete the requested changes in the current sprint. And additions should generally be new stories unless the team feels they have the time and it would be easier for them to do it during the current sprint.
So the overall answer, is "it depends", but I think using the above guidelines will help everyone make the best decision for the team.
You can cancel a sprint. Or possibly move the troublesome items to a new sprint perhaps? Thereby reducing the length of the current sprint. But in essence I say, anything that affects the length or the output of the sprint drastically would be our decision point. Only you can really asses that I would say.

Resources