Got an error when compiling our code:
In Windows 7 and visual studio, I at first did not notice the problem, but it was giving a warning:
LNK4042: object specified more than once; extras ignored
In Linux and gcc it gave an error, so I could not compile the code:
multiple definition of `<constructor of class>'
collect2: ld returned 1 exit status
I took som time to figure it out, but turned out to be a bad merge in subversion,
the *.pro file had the same class twice in
HEADERS += \ Class1.h /
Class1.h
SOURCES += \ Class1.cpp /
Class1.cpp
Rremoving the second time the class name where entered in the *.pro file solved the problem.
See http://stackoverflow.com/questions/4722400/qt-compiler-warning-overriding-commands-for-target-ignoring-old-commands-for
Showing posts with label Qt. Show all posts
Showing posts with label Qt. Show all posts
Sunday, November 02, 2014
Thursday, October 02, 2014
Qt and collect2 ld returned exit status 1
Got this error when building a unit test project:
collect2 ld returned exit status 1
The linker complained on my newly added class in the implementation project.
It took a while to figure it out, but the problem was that the old *.so file was left in Build folder when I tried to compile the lib file that was used by the unit test project.
The solution to the problem was to remove all files in the implementation project build folder. Followed by a rebuild of the implementation project and unit tests project could be built without any linker errors.
collect2 ld returned exit status 1
The linker complained on my newly added class in the implementation project.
It took a while to figure it out, but the problem was that the old *.so file was left in Build folder when I tried to compile the lib file that was used by the unit test project.
The solution to the problem was to remove all files in the implementation project build folder. Followed by a rebuild of the implementation project and unit tests project could be built without any linker errors.
Saturday, September 06, 2014
Solved: error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
Added two classes A and B both inheriting QObject.
The compiler started complaining:
error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
It complains because:
"The values stored in the various containers can be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator."
http://qt-project.org/doc/qt-4.8/containers.html
Solved the error by changing the QList to be a list of QSharedPointer:
#include <QObject>
#include "b.h"
class A : public QObject
{
Q_OBJECT
public:
explicit A(QObject *parent = 0);
QList<B> doStuff();
signals:
public slots:
};
But when adding implementation for A:#include <QObject>class B : public QObject{Q_OBJECTpublic:explicit B(QObject *parent = 0);signals:public slots:};
QList<GUIContainer> A::doStuff()
{
QList<B> list;
return list;
}
The compiler started complaining:
error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
It complains because:
"The values stored in the various containers can be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator."
http://qt-project.org/doc/qt-4.8/containers.html
Solved the error by changing the QList to be a list of QSharedPointer:
QList<QSharedPointer<B> > doStuff();
Thursday, August 21, 2014
SIGSEGV horror in the Qt project.
Had some problems in our project the application kept crashing with SIGSEGV error. We did not get a chance to catch the problem in the debugger making it hard to find. Found a neat trick on the internet, it's possible to add a handler for signals that catch the SIGSEGV and can print the stacktrace:
http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
It's also possible to catch other signals:
http://qt-project.org/doc/qt-4.8/unix-signals.html
http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
#include <stdio.h> #include <execinfo.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void handler(int sig) { void *array[10]; size_t size; // get void*'s for all entries on the stack size = backtrace(array, 10); // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, STDERR_FILENO); exit(1); } void baz() { int *foo = (int*)-1; // make a bad pointer printf("%d\n", *foo); // causes segfault } void bar() { baz(); } void foo() { bar(); } int main(int argc, char **argv) { signal(SIGSEGV, handler); // install our handler foo(); // this will call foo, bar, and baz. baz segfaults. }
It's also possible to catch other signals:
http://qt-project.org/doc/qt-4.8/unix-signals.html
Saturday, August 09, 2014
Qt connect is complaining that it can't find slot in super class when connecting sub class
Got an runtime error in the Qt application we are building, were connecting a signal with a slot, but when running the app we got this error message in the console:
Object::connect: No such slot mgccis::web::SuperClassWebservice::onReadyRead() in ServiceInterface\SubClassWebservice.cpp:37
The connect code in the SubClassWebservice looked like this:
There was a slot in the subClassWebservice, took a google search session to find out the real problem, found this on Stackoverflow:
http://stackoverflow.com/questions/4322224/qt-slots-and-inheritance-why-is-my-program-trying-to-connect-to-the-parent-inst
I've forgot to add the Q_OBJECT in the class declaration of the sub class.
Object::connect: No such slot mgccis::web::SuperClassWebservice::onReadyRead() in ServiceInterface\SubClassWebservice.cpp:37
The connect code in the SubClassWebservice looked like this:
connect(httpPost_parameterData_.data(), SIGNAL(readyRead()), this, SLOT(onReadyRead()));
There was a slot in the subClassWebservice, took a google search session to find out the real problem, found this on Stackoverflow:
http://stackoverflow.com/questions/4322224/qt-slots-and-inheritance-why-is-my-program-trying-to-connect-to-the-parent-inst
I've forgot to add the Q_OBJECT in the class declaration of the sub class.
Thursday, July 31, 2014
Change color on SVG item in Qt
This is a neat trick that can be good to know, found the solution in StackOverflow:
http://stackoverflow.com/questions/15123544/change-the-color-of-an-svg-in-qt/15124080#15124080
If you have for example an arrow that needs to be in different colors at different times in a Qt application, it's possible to change the color of an SVG item instead of adding several SVG items with different colors.
http://stackoverflow.com/questions/15123544/change-the-color-of-an-svg-in-qt/15124080#15124080
If you have for example an arrow that needs to be in different colors at different times in a Qt application, it's possible to change the color of an SVG item instead of adding several SVG items with different colors.
QColor weightOutreachSupportArrowHorisontalColor = getWeightOutreachSupportArrowHorisontalColor();
yAxisIndicator_ = QSharedPointer<QGraphicsSvgItem>(new QGraphicsSvgItem(":/Icon/Icon/Arrow_x_30_30.svg",0));
QGraphicsColorizeEffect* weightOutreachSupportArrowHorisontalColorEffect = new QGraphicsColorizeEffect();
weightOutreachSupportArrowHorisontalColorEffect->setColor(weightOutreachSupportArrowHorisontalColor);
yAxisIndicator_->setGraphicsEffect(weightOutreachSupportArrowHorisontalColorEffect);
yAxisIndicator_->setZValue(100);
yAxisIndicator_->rotate(90);
yAxisIndicator_->setVisible(false);
scene_->addItem(yAxisIndicator_.data());
Monday, July 28, 2014
How to in Qt *.Pro-file disable: warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
Got a compiler error when using sscanf in QT Creator:
warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
To make sure other warnings wont't disappear in the spam like messages caused by the c++ compiler, we wanted to disable the warning.
Tried to do add this at the top of the main.cpp file but got the same error:
#define _CRT_SECURE_NO_WARNINGS
Adding this in the *.PRO file did the trick:
warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
To make sure other warnings wont't disappear in the spam like messages caused by the c++ compiler, we wanted to disable the warning.
Tried to do add this at the top of the main.cpp file but got the same error:
#define _CRT_SECURE_NO_WARNINGS
Adding this in the *.PRO file did the trick:
#Removes: warning: C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
win32:{
DEFINES += _CRT_SECURE_NO_WARNINGS
}
Saturday, May 17, 2014
Solved: Qt Segmentation fault on MainWindow show() on line: inline void show() { setVisible(true); }
Writing this down so I'll remember in the future.
The application worked in Qt Creator in Windows, but in Linux we received Segmentation Fault when trying to run the application in the debugger.
Looking at the stacktrace only showed that it crashed in SetVisible on the main window.
0 __strlen_sse2 strlen.S 99 0x7e9520
1 XSetCommand /usr/lib/libX11.so.6 0xdbbb9f
2 XSetWMProperties /usr/lib/libX11.so.6 0xdc0601
3 QWidgetPrivate::create_sys(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x110db5e
4 QWidget::create(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10bc73c
5 QWidget::setVisible(bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10c20e5
6 QWidget::show qwidget.h 494 0x804fd0c
7 mgccis::shell::MainApplication::InitializeInterface mainapplication.cpp 29 0x804facc
8 main main.cpp 25 0x804efb0
It stopped on the line below, it made no sense all objects where initialized:
#ifndef Q_WS_WINCE
inline void show() { setVisible(true); }
#else
void show();
#endif
After some googling of the subject I found this forum post that described a problem that can cause this error message, it's the signature on the MainApplication that can causes the problem:
http://www.qtcentre.org/archive/index.php/t-45135.html?s=ea17a4ab05c00533d49f938c1da47077
But our solutionwas the opposite from the resolution in the forum post. We have our own builder class that gets the arguments from the main method and that passes the argument to the MainApplication, so in our case the solution was to send the argc parameter as value instead of a reference:
So the Change was from:
explicit MainApplication(int &argc, char* argv[]);
To this:
explicit MainApplication(int argc, char** argv);
After the change the application can be debugged in Windows and Linux and the error message made sense, we sent a reference to a temporary instance of the argc to the MainWindow that used when window is shown.
The application worked in Qt Creator in Windows, but in Linux we received Segmentation Fault when trying to run the application in the debugger.
Looking at the stacktrace only showed that it crashed in SetVisible on the main window.
0 __strlen_sse2 strlen.S 99 0x7e9520
1 XSetCommand /usr/lib/libX11.so.6 0xdbbb9f
2 XSetWMProperties /usr/lib/libX11.so.6 0xdc0601
3 QWidgetPrivate::create_sys(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x110db5e
4 QWidget::create(unsigned long, bool, bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10bc73c
5 QWidget::setVisible(bool) /opt/qt-4.8.4/lib/libQtGui.so.4 0x10c20e5
6 QWidget::show qwidget.h 494 0x804fd0c
7 mgccis::shell::MainApplication::InitializeInterface mainapplication.cpp 29 0x804facc
8 main main.cpp 25 0x804efb0
It stopped on the line below, it made no sense all objects where initialized:
#ifndef Q_WS_WINCE
inline void show() { setVisible(true); }
#else
void show();
#endif
After some googling of the subject I found this forum post that described a problem that can cause this error message, it's the signature on the MainApplication that can causes the problem:
http://www.qtcentre.org/archive/index.php/t-45135.html?s=ea17a4ab05c00533d49f938c1da47077
But our solutionwas the opposite from the resolution in the forum post. We have our own builder class that gets the arguments from the main method and that passes the argument to the MainApplication, so in our case the solution was to send the argc parameter as value instead of a reference:
So the Change was from:
explicit MainApplication(int &argc, char* argv[]);
To this:
explicit MainApplication(int argc, char** argv);
After the change the application can be debugged in Windows and Linux and the error message made sense, we sent a reference to a temporary instance of the argc to the MainWindow that used when window is shown.
Wednesday, April 23, 2014
Error: Loading plugin error: Cannot load library /usr/local/SomeLib/libSomeLib.so.1.0.0: (/usr/local/SomeLib/libSomeLib.so.1.0.0: undefined symbol: _ZN18SomePluginModuleD1Ev)
Got this annoying error in QPluginLoader when I deployed and tried to run the application. It took a while before i realized what my mistake was.
I accidentally missed to add a implementation for the destructor and that caused the error message, found this forum post that got me in the right direction:
http://www.qtcentre.org/threads/17253-QPluginLoader-doesn-t-load-plugin
.h with destructor:
~SomePluginModule();
.cpp did not have:
SomePluginModule::~SomePluginModule()
{
//clean up...
}
I accidentally missed to add a implementation for the destructor and that caused the error message, found this forum post that got me in the right direction:
http://www.qtcentre.org/threads/17253-QPluginLoader-doesn-t-load-plugin
.h with destructor:
~SomePluginModule();
.cpp did not have:
SomePluginModule::~SomePluginModule()
{
//clean up...
}
Friday, February 14, 2014
Solved: error: no match for call to '(QString) (QString&)' when emitting signal in Qt
I had an annoyning error message:
error: no match for call to '(QString) (QString&)'
when compiling my qt application.
Took some time before I found what was wrong, the code looked like this:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit newValue(value_);
}
The error is that the signal name is the same as the variable:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit newValue(value_);
}
So the fix is easy, changed the signal name:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit updateValue(value_);
}
error: no match for call to '(QString) (QString&)'
when compiling my qt application.
Took some time before I found what was wrong, the code looked like this:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit newValue(value_);
}
The error is that the signal name is the same as the variable:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit newValue(value_);
}
So the fix is easy, changed the signal name:
QString newValue=QString::number(value,'g',1);
if(newValue != value_)
{
value_ = newValue;
emit updateValue(value_);
}
Subscribe to:
Posts (Atom)