error finding in QT - qt

In QT-creator I am getting the following error:
ASSERT failure in QVector::operator[]: "index out of range", file c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qvector.h, line 359
My problem is that it does not specify which QVector is out of range... Even when I run in debug mode I cannot find the location of the error. Is there a way to easily find the error? The code is quite huge and the error only pops up every once in a while so it would be a lot of work to check every qVector I use separately.

Assuming you are using Qt Creator, there is a "Stack" window which shows the function calls which led to the point where your program stopped:
In that window, double click the first file which you know is your own file, in that screenshot it is main.cpp in line 5. The file will open and a yellow arrow will be shown. The line which caused the assertion is the line above that yellow arrow (That arrow actually points to the next statement which would have been executed)

Related

Qt error is printed on the console; how to see where it originates from?

I'm getting this on the console in a QML app:
QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0
The app is not crashing so I can't use the debugger to get a backtrace for the exception. How do I see where the error originates from?
If you know the function the warning occurs in (in this case, QFont::setPointSizeF()), you can put a breakpoint there. Following the stack trace will lead you to the code that calls that function.
If the warning doesn't include the name of the function and you have the source code available, use git grep with part of the warning to get an idea of where it comes from. This approach can be a bit of trial and error, as the code may span more than one line, etc, and so you might have to try different parts of the string.
If the warning doesn't include the name of the function, you don't have the source code available and/or you don't like the previous approach, use the QT_MESSAGE_PATTERN environment variable:
QT_MESSAGE_PATTERN="%{function}: %{message}"
For the full list of variables at your disposal, see the qSetMessagePattern() docs:
%{appname} - QCoreApplication::applicationName()
%{category} - Logging category
%{file} - Path to source file
%{function} - Function
%{line} - Line in source file
%{message} - The actual message
%{pid} - QCoreApplication::applicationPid()
%{threadid} - The system-wide ID of current thread (if it can be obtained)
%{qthreadptr} - A pointer to the current QThread (result of QThread::currentThread())
%{type} - "debug", "warning", "critical" or "fatal"
%{time process} - time of the message, in seconds since the process started (the token "process" is literal)
%{time boot} - the time of the message, in seconds since the system boot if that can be determined (the token "boot" is literal). If the time since boot could not be obtained, the output is indeterminate (see QElapsedTimer::msecsSinceReference()).
%{time [format]} - system time when the message occurred, formatted by passing the format to QDateTime::toString(). If the format is not specified, the format of Qt::ISODate is used.
%{backtrace [depth=N] [separator="..."]} - A backtrace with the number of frames specified by the optional depth parameter (defaults to 5), and separated by the optional separator parameter (defaults to "|"). This expansion is available only on some platforms (currently only platfoms using glibc). Names are only known for exported functions. If you want to see the name of every function in your application, use QMAKE_LFLAGS += -rdynamic. When reading backtraces, take into account that frames might be missing due to inlining or tail call optimization.
On an unrelated note, the %{time [format]} placeholder is quite useful to quickly "profile" code by qDebug()ing before and after it.
I think you can use qInstallMessageHandler (Qt5) or qInstallMsgHandler (Qt4) to specify a callback which will intercept all qDebug() / qInfo() / etc. messages (example code is in the link). Then you can just add a breakpoint in this callback function and get a nice callstack.
Aside from the obvious, searching your code for calls to setPointSize[F], you can try the following depending on your environment (which you didn't disclose):
If you have the debugging symbols of the Qt libs installed and are using a decent debugger, you can set a conditional breakpoint on the first line in QFont::setPointSizeF() with the condition set to pointSize <= 0. Even if conditional breakpoints don't work you should still be able to set one and step through every call until you've found the culprit.
On Linux there's the tool ltrace which displays all calls of a binary into shared libs, and I suppose there's something similar in the M$ VS toolbox. You can grep the output for calls to setPointSize directly, but of course this won't work for calls within the lib itself (which I guess could be the case when it handles the QML internally).

run monkey_recorder.py error: mismatched input 'monkey_recorder' expecting NEWLINE

When I tried to use monkeyrunner command to run recorder, I got the error: mismatched input 'monkey_recorder' expecting NEWLINE.
Here is screenshot of my command.
enter image description here
You should try AndroidViewClient/culebra which will give you some advantages over monkeyrunner and monkey_recorder. For example, instead of recording the screen coordinates for a touch, culebra records the selector of the View touched so the script or test will be screen coordinates agnostic.
See Culebra GUI page for details.

Corrective Feedback (Picture as Feedback) in Psychopy

I am creating an experiment with the PsychoPy Builder.
I have visual and auditory stimuli, the task is to learn associations between them.
When the participant presses the right key, the answer "Correct" appears. However, when the participant presses the wrong key, I would like to not only display "Wrong." But also: "The correct answer is ..." and then show the picture or the sound of the correct association.
I have created a routine that is called "Feedback". It contains the Code component, the Text component and the Picture component (or the sound component).
In the condition file (.xlsx), the picture (sound) that should be displayed is called "corrective_FB".
In the Code Component in "Begin Experiment", I have
message=''
In the Code Component I have written the following code in the "Begin Routine":
if Antwort_manuell.corr:#stored on last run routine
message="Richtig!"
else:
message="Ups, das war falsch. Die richtige Antwort wäre:"
Form_stimulus2.setImage(corrective_FB)
I guess, I am not doing the "display image" command correctly. How is the correct command? And how is it for an auditory stimulus?
When I run the experiment, it seems to work when I press the correct keypress (however, the picture is shown then, too and it should only be the text....), but when I press the wrong key, the experiment stops.
When I force it to end, I get the follwing message:
Running: C:\Dateien\Forschung\Experimente\Legasthenie_Crossmodal\Experiment\Visual_manual\Vis_Man_lastrun.py
Traceback (most recent call last)
File "C:\Dateien\Forschung\Experimente\Legasthenie_Crossmodal\Experiment\Visual_manual\Vis_Man_lastrun.py", line 406, in
Feedbacktext.setText(message)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.82.01-py2.7.egg\psychopy\visual\text.py", line 240, in setText
setAttribute(self, 'text', text, log)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.82.01-py2.7.egg\psychopy\tools\attributetools.py", line 100, in setAttribute
setattr(self, attrib, value) # set attribute, calling attributeSetter if it exists
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.82.01-py2.7.egg\psychopy\tools\attributetools.py", line 20, in __set__
newValue = self.func(obj, value)
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.82.01-py2.7.egg\psychopy\visual\text.py", line 231, in text
self.dict['text'] = unicode(text)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 43: ordinal not in range(128)
Exception UnicodeDecodeError:
Thank you all for your help. I finally got it work. I indeed had to mark the message as a unicode string.
And I had to define more explicitly how the stimulus will be shown for correct and wrong answers.
I don't know, if I did it the most intelligent way, but it works. I am thankful for suggestions how it can be done more "beautifully", but this is how my code looks like now:
if Antwort_manuell.corr:#stored on last run routine
message="Richtig!"
Form_stimulus2.size = 0
else:
message=u"Ups, das war falsch. Die richtige Antwort wäre:"
Form_stimulus2.setImage(corrective_FB)
Form_stimulus2.size = 5
And for the sound the code is:
if key_tester.corr:#stored on last run routine
message="Richtig!"
sound_1.volume = 0
else:
message=u"Ups, das war falsch. Die richtige Antwort wäre:"
sound_1.setSound(corrective_FB)
sound_1.volume = 1

Issues with Zsh prompt

My Zsh prompt cursor is sometimes (most of the time actually) a line below were it should be (attaching screenshot):
If I hit enter multiple times, the prompt seems to get fixed:
My first thought is that it was an error within my custom prompt, so I replaced by prompt with a simple one containing only one digit:
PROMPT='> '
But the error persisted.
Any clues about what can be missing?
You can find my theme here: http://pastebin.com/cSJwGWKZ.
Notice that I'm using Oh My Zsh.
EDIT: The prompt seems to get fixed when I reach the bottom of the terminal (by hitting enters).
The culprit is %{$(echotc DO 1)%} in your RPROMPT, which moves the cursor one line down when printing RPROMPT. When reaching the bottom of your terminal there is no additional line to go down to, so the cursor just remains where it was.
Depending on where you want your RPROMPT you have basically two options:
On the same line as your input cursor (after λ):
Just remove %{$(echotc DO 1)%} from your RPROMPT:
RPROMPT='$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%'
One line (or any other number of lines, really) above your input:
Add %{$(echotc UP 1)%} at the beginning of your RPROMPT, this will move the cursor up one line, print the right prompt and move back down one line:
RPROMPT='%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}'`
Note: the second method may lead to RPROMPT overwriting parts of PROMPT if both get to long and/or the terminal window to narrow. If RPROMPT remains on the same line as input, it will be hidden once the input reaches it (and will reapper if you delete some of the input).

Qt moc error 1 - what does it mean?

I'm trying to build a project on Mac OSX, and it's giving me a cryptic error:
[moc_droparea.cpp] Error 1
droparea.cpp is (obviously) a file in the project. I checked that it exists in the project directory and is not corrupted. The file moc_droparea.cpp doesn't show up in the build folder after this error, so I'm assuming it's failing to build for whatever reason, but the error is too vague to help me figure out what's going on. Could anyone help me figure out what this means please?
Click on "compile output", scroll up and click the red line.
In my case the Red line was saying: You cant define an integer value in private slots..
Under the qt creator window, in "progress details" section, there is a button named "compile output" (button number 4). Errors are explained there with red font. Click it and scroll up.
The solution was annoyingly simple. I had a folder structure that put spaces (illegal characters) in the file path. I put underscores instead of spaces and it built fine. I would think the moc pre-processor could handle spaces in file names, but apparently not. I feel foolish, but at least the problem is solved now.
Hopefully this solution can help someone else.
This can be because of few other things as others have mentioned. I would like to add another one which is missing here.
You will get a "moc error 1" in case you create a class and add Q_OBJECT to it but do not inherit from QObject.
If you take a look at Compile Output there is a line saying:
Error: Class contains Q_OBJECT macro but does not inherit from QObject
Hence, the general approach to fix this problem is just taking a look at "Compile Output" window.
This can be because of many things I guess - I had a similar situation where I forgot to remove an entry in the .qrc file that didn't exist anymore.
So check your resource paths as well.
You can right click on the error 1 and select 'View output'. In my case, I had a bad file name in my qrc file.
Like J.Javan already pointed to, it might be helpful to check also the compiler output. In my case I found:
../stateMaschine/usermenu.h:57: Error: Class declarations lacks
Q_OBJECT macro. make: *** [Makefile:215: moc_usermenu.cpp] Error 1
So this helped me to fix the error by correction of the class declaration when using signals and slots:
class Menu : public QObject{
Q_OBJECT
...
Same Error 1 occured to me due to a ressource file (.qrc) which referred to a file name beginning with a period. When I removed the period from the file name, compilation worked again. Interestingly, the error only occured under Mac OSX using the Clang compiler. On Windows using the gcc compiler, the file name did not provoke an error.
Maybe the "[source file name] Error 1" message in general means that a file could not be found due to unexpected characters in the file path.
In my case, I ran out of space on SD card causing this sort of error.

Resources