Strange and unknown error while compiling QT code - qt

I don't know why I am getting error or these statements. The same code works fine when I compile it for x86_64 system but when I changed target to Beaglebone Black and switched to angstrom tool chain the QTcreator started giving error in these lines.
//connect(process, &QProcess::readyReadStandardError, [=]{
ui->textBrowser->append(process->readAllStandardError());
});
connect(process, &QProcess::readyReadStandardOutput, [=]{
ui->textBrowser->append(process->readAllStandardOutput());
});
Errors are for the expression "[=]". Infact I don't know why this error is coming. Could this be related to version, bcoz BBB is have qt4-embedded. Any help would be appreciated.

The syntax for connecting signal to c++11 lambda has been added to Qt 5. Since previous version (Qt4) doesn't define the right signature for connect(), you can't use it. You should transform your code to match the correct syntax:
connect(process, SIGNAL(readyReadStandardError()), receiver, SLOT(yourCustomSlot()) );
With a slot declared as follow:
class MyReceiverClass {
slots:
void yourCustomSlot() {
ui->textBrowser->append(process->readAllStandardOutput());
}
};

Related

Clang static analyzer (clazy) ignores NOLINT and similar meta instructions in Qt code

I need to switch off some warnings that the Clang static analyzer (clazy) flags in some Qt code that I work with.
Appending '// NOLINT' as a comment to code lines that get flagged by clazy does not work, apparently because Qt is transformed to C++ code before clazy gets to see it, dispensing with all comments and pragmas. Appending '// clazy:exclude...' does not work either, and likewise with
#if defined(__clang__) // if that is even the right define to look for
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-W..."
#endif
...
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
Is there any elegant way of getting rid of clazy warnings in Qt code? I would prefer it to be applicable to individual lines as opposed to disabling warnings on entire files.
You should use
<your code> // clazy:exclude=<warning>,<another warning>
For example, I get clazy-strict-iterators warning in my code.
I've added // clazy:exclude=strict-iterators in the end of line, and the warning is gone.
Note that you should not add clazy- prefix to the warning name.
Source: https://blogs.kde.org/2016/04/25/clazy-suppressing-warnings

QOpenGLShaderProgram: is possible to make error output nice?

I'm implementing some numerical algorithms on GPU via OpenGL and Qt.
But i am not very familiar with it.
I want to extract some functions from my current shader to some "shader library" and use it in my other shaders by string interpolation. It not hard to implement but i don't know how handle shader's compile errors
I use following code to compile shader
QOpenGLShaderProgram *shaderProgram = new QOpenGLShaderProgram();
if (!shaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment,fragmentShaderFileName)) {
qDebug() << "Failed to compile fragment shader";
//..........
When some compile error appears Qt print following message (an example)
QOpenGLShader::compile(Fragment): 0:331(9): error: syntax error, unexpected NEW_IDENTIFIER, expecting ',' or ';'
*** Problematic Fragment shader source code ***
//my shader source code
Is possible to catch error line number and use it to build my own error message? (with highlighted line)
According to the Qt documentation, you can use QOpenGLShaderProgram::log():
Returns the errors and warnings that occurred during the last link()
or addShader() with explicitly specified source code.
You can then parse the resulting string to build your own error message.

Coding errors between the Arduino Uno and SDI-12 interface on Decagon Devices

I have been working on a project recently using a sensor for electrical conductivity in soil (A 5TE sensor from Decagon Devices) with my Arduino Uno. I am ready to code, and found this example code on GitHub (the example code is there when you scroll down the page). When trying to run it on the latest version of Arduino, it gave me these compilation errors:
sketch_dec15a:7: error: expected initializer before 'void'
sketch_dec15a:4: error: 'SDISerial' does not name a type
sketch_dec15a:9: error: expected initializer before 'void'
sketch_dec15a.ino: In function 'void loop()':
sketch_dec15a:22: error: 'connection' was not declared in this scope
NOTE: I believe I installed the library correctly, but am not 100% certain...more like 85%.
What's wrong with the code and how can it be made to work?
The example code is wrong. Look at the compilation errors. The first thing it says is:
sketch_dec15a:7: error: expected initializer before 'void'
So what it's saying is that it found something that said void and expected to see something else first. void occurs only twice in your code, so we can't be far. Let's take a look at the code immediately surrounding it the first void:
char tmp_buffer[4];
char sensor_info[]
//initialize variables
void setup(){
connection.begin();
Serial.begin(9600);//so we can print to standard uart
//small delay to let the sensor do its startup stuff
delay(3000);//3 seconds should be more than enough
}
Right before the void setup(){ is //initialize variables. That's just a comment, and not code, so it doesn't relly count. Looking back one more line we see:
char sensor_info[]
Something is wrong with that line. Work on it and see if you can figure it out (check the other lines for "hints"). If you can't figure it out, the answer is right below (put your mouse over it to see it):
It needs a semicolon ";" at the end to complete the statement. Because the semicolon is missing, it thinks "void setup(){" is part of the previous statement.

What API does Qt use for interacting with the Windows clipboard?

I've been browsing the Qt source code trying to find the actual system calls but it seems Qt doesn't use the Windows API documented on MSDN. For example grepping the source for "GetClipboardData" returns results in two files:
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
HANDLE clipData = GetClipboardData(CF_TEXT)
qaxserverbase.cpp:
STDMETHOD(GetClipboardData)(DWORD dwReserved, IDataObject** ppDataObject);
...
HRESULT WINAPI QAxServerBase::GetClipboardData(DWORD, IDataObject**)
{
return E_NOTIMPL;
}
and "SetClipboardData":
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
result = SetClipboardData(CF_UNICODETEXT, wcsdup(reinterpret_cast<const wchar_t *> (data->text().utf16()))) != NULL;
Neither of which seems useful, since they're being declared for Win CE/Mobile.
My Qt (4.8.1) uses OleSetClipboard and OleGetClipboard. The lines you got to are never reached in regular windows, as only in case of #if defined(Q_OS_WINCE) Qt uses #define OleSetClipboard QtCeSetClipboard and #define OleGetClipboard QtCeGetClipboard, and otherwise uses system-provided versions of those functions.
It was a little dificult to see this #if defined though, so you are excused ;)
It is so at least on my Qt version. If you are talking about qt, and especially about it's internals, you should menstion the version, right?

including Qt headers in DLL

I have a DLL in wich I would like to take a reference to a QObject and manipulate it, without actually creating an interface. So, I included "Qt/qobject.h" and compiled, but the compiler (Visual Studio 2008 pro) gives me syntax errors. It looks like it doesn't recognize the QThread object. How do I use a QObject in my dll? Is this even possible? Do I have to start my program from a Qt app? I'm actually trying to set a system-wide hook and get 3rd application QWidgets to manipulate... Any idea how I can use QObject in my dll?
Here are the errors:
1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
1>Compiling...
1>FTClient.cpp
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
1>FroggerDLL - 6 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
Any help would be greatly appreciated,
Thanks
Dave
What's on line 154? Mine is just the declaration
QThread* thread() const;
but that's 4.5.1 on Linux so it might be different. The first reference to anything involving the token type is on line 204 which is a variable of type Qt::ConnectionType.
BTW. I just tried compiling the following on my system ( in the file incqobj.cpp )
include <QOObject>
QObject myQOject;
with
g++ -I/usr/lib/qt4/include -I/usr/lib/qt4/include/QtCore -c incqobj.cpp
and it compiled fine so it should be as simple as that.
Edit: Since Jesse confirms that it works for him on Windows I'm tempted to say that you've got a non-Qt macro coming in and interfering. One thing you could do is a sanity check on what the compiler is actually seeing by getting VS to only produce the preprocessed source rather than do the compilation.
I haven't used VS in years but I think the option is \E maybe?
[Edit: see the 2nd comment by Jesse, it should be /E] It may also be an explicit option now in the compiler properties which can be set for that source file. Can't remember where it puts the output either so you may need to hunt around for it a bit! If you get that going though you can check to see if the code looks right at the part that would correspond to line 154 in the original QObject header.
Thanks for all the help, solution: I had to include the Qt headers before all my other includes, and it now compiles.
Thanks again!
Try including QThread?
#include <QThread>
Qt uses forward declaration extensively and sometimes you need to include extra headers.
EDIT:
Do you set any defines? Here is what I have for my 2003 Qt commercial (4.3.4) project (executable that links to Qt dlls):
QT_LARGEFILE_SUPPORT
QT_DLL
QT_GUI_LIB
QT_CORE_LIB
QT_THREAD_SUPPORT
QT_NETWORK_LIB

Resources