QCameraImageCapture() no matching function - qt

I get the error,
error: no matching function for call to 'QCameraImageCapture::QCameraImageCapture()'
Simply by having the code,
#include <QCamera>
#include <QCameraImageCapture>
class Webcam : public QObject
{
Q_OBJECT
public:
Webcam();mageCaptured();
private:
QCameraImageCapture _imageCamera;
};
I have written no other code. Any idea what's going on here? It worked for QCamera _camera;
EDIT:
Sorry, this is completely my fault. Too much time using Python made me forget all about pointers.

QCameraImageCapture doesn't have a default constructor, see the documentation here, so you must pass a QMediaObject pointer to the constructor of QCameraImageCapture (QCamera inherits from QMediaObject so it can be used there)
Quote from documentation:
The QCameraImageCapture class is a high level images recording class. It's not intended to be used alone but for accessing the media recording functions of other media objects, like QCamera.

Related

Qt: Signals and Slots in QGraphicsPixmapItem class

I have inherited a class called GraphicsPixmapItem from QGraphicsPixmapItem in order to override/create some mouse events. The problem is that I want to emit a signal after some calculations are performed, but it looks like it's not possible unless some hacks are performed, since this class is not a QObject.
To do so, I have tried to inherit the aformentioned new class from QObject as well, but I keep getting compiler errors.
My attemp:
Header file (graphicspixmapitem.h):
#ifndef GRAPHICSPIXMAPITEM_H
#define GRAPHICSPIXMAPITEM_H
#include <QObject>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
class GraphicsPixmapItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
public:
explicit GraphicsPixmapItem(QGraphicsItem *parent = 0);
virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent);
signals:
void translationVector(QPointF info);
};
#endif // GRAPHICSPIXMAPITEM_H
Source file (graphicspixmapitem.cpp):
#include "graphicspixmapitem.h"
GraphicsPixmapItem::GraphicsPixmapItem(QGraphicsItem *parent) :
QGraphicsPixmapItem(parent)
{
}
void GraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
//Code
}
void GraphicsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
{
QPointF info;
//Code
emit(translationVector(info));
}
And I get the following linker errors:
undefined reference to `vtable for GraphicsPixmapItem'
undefined reference to
`GraphicsPixmapItem::translationVector(QPointF)'
Any clue about how to proceed accordingly?
Side note:
I am aware that QGraphicsObject may be a good alternative, but as discussed here, performance looks severely affected by the amount of signals that are emitted when operating with them, where most of them will not be used in my case. This is the reason why I prefer to create my own class with base QGraphicsItem, instead of QGraphicsObject.
Many thanks in advance.
It looks like the meta object compiler (moc) wasn't run over the code, or that moc's result wasn't included when linking.
Have you added graphicspixmapitem.h to qmake's HEADERS variable?
Have you re-run qmake and tried a clean build in general?
Is moc run on graphicspixmapitem.h? Check your compile log.
Is graphicspixmapitem_moc.o included when linking? Check your compile log.
I have finally found out the problem involving the linkage error. In this sense, I must give my thanks to Thomas McGuire for pointing out the key idea to look for the source of the problem.
The reason is that few days ago I attempted to subclass QGraphicsPixmapItem (for other purposes) with the exact same name than this one, namely, GraphicsPixmapItem (with header file graphicspixmapitem.h and source file graphicspixmapitem.cpp).
When I did that, I finally figured out that I could do things in a different way and I no longer needed that inherited subclass, hence I removed these files from the project. But doing this is a major mistake if you do not make sure to clean the project before removing the files from the project, because the files generated by qmake and moc (*.o, moc_*.cpp, moc_*.o) will remain in the build/debug directory unless you remove them by hand, because they will not be deleted by cleaning the project.
Therefore, it looks like in that situation, qmake detects that the files already exist and it does not generate the correct ones from the updated class, causing the linking error expounded above.
In summary, if you are going to delete some files from your project, make sure to clean it previously, especially if you are going to remove a class with the Q_OBJECT macro.

Qt GUI Dialog Initialization Confusion

I am learning GUI coding with Qt and hope to clear up some confusion on my part. When I create a dialog with Qt Creator it creates code for me like this...
#ifndef LISTDIALOG_H
#define LISTDIALOG_H
#include <QDialog>
#include "ui_listdialog.h" //Q1:Why was this auto paced in cpp file instead of h file?
//Q2: This is what I'm really confused about.
//Is Ui namespace wrapping ui_listdialog class or the ListDialog class?
namespace Ui {
class ListDialog;
}
class ListDialog : public QDialog
{
Q_OBJECT
public:
explicit ListDialog(QWidget *parent = 0); //Q3: Why is this constructor explicit?
~ListDialog();
//CUSTOM FUNCTIONALITY NOT ADDED BY CREATOR (IGNORE FOR MY POST)
private slots:
void addItem();
void editItem();
void deleteItem();
//END CUSTOM FUNCTIONALITY
private:
Ui::ListDialog *ui; //Placed on heap instead of stack.
};
#endif // LISTDIALOG_H
There are things in the above code that differ from my 3 Qt books (all 3 out of date and ignore Creator).
My main confusion comes from Q2. Is "Ui" wrapping "ui_listdialog.h" or the class I have posted here ( class ListDialog )? The syntax seems to imply to me that it is wrapping the latter but I feel it must be actually wrapping the ui_listdialog.h class instead. Very confused about this. Can someone explain this clearly?
I also don't understand why the constructor was made explicit by Creator. I have not seen that in any of the 3 books.
Q1. The #include is placed in the .cpp to avoid too many dependencies in the header file. This shortens compilation time, because if you change the dialog, the only thing you have to recompile is the .cpp and not everything that includes your header file. In general, if a forward declaration of a class is enough (i.e. you only have a pointer or a reference to it in your class), then it's better not to #include the class's definition.
Q2. Ui is a namespace that contains a different class called ListDialog. You can open the header file and see the definition of this other class. A bit confusing until you get used to it.
Q3. It's a good habit to use the explicit keyword with constructors that take a single parameter. Otherwise the constructor can also be used as an automatic conversion operator, and this can cause problems if you're not aware of it. For example, if you have a function that takes a ListDialog parameter, and you pass a QWidget * parameter, it may call the constructor when in fact you want the compiler to shout (invalid parameter).
The ui_listdialog.h contains implementation to generate your user interface based on Qt Designer. It isn't necessary when declaring the class -- that's why the file was #included in the .cpp (Q1). Without the ui_listdialog.h in the header, the class declaration is necessary (Q2).
As for Q3, it's probably there to make you use the constructor syntax. Else, you could write misleading statements like
ListDialog dialog = parentDialog ;

QML : How to read a QList from C++

I have a simple need : I have defined a C++ class
class MyClass: public QDeclarativeItem
{
Q_OBJECT
public:
MyClass(QDeclarativeItem * parent=0);
...
private:
QList<QString> mList
}
And of course, I've registered it : qmlRegisterType<MyClass>(...)
I want to access in the QML code to my QList<QString> mList. How can I do it?
It annoys me as it looks like a simple problem, but I can't find anything about this. (I can create a Q_INVOKABLE slot, but I can't read the results, etc...)
Edit : QML supported Data Types
I don't think that QList is a supported data type for Qt's QML binding. I've had similar problems interfacing between C++ and JavaScript using the QtWebkit Bridge.
If possible, try using a QVariantList instead of a QList. Although this is technically a typedef for QList<QVariant> I think it should work.
If you need a custom type in your list (not just strings or other basic types) there's QDeclarativeListProperty for that case.
But it's more complicated, see http://doc.qt.nokia.com/4.7/declarative-tutorials-extending-chapter5-listproperties.html

In Qt, how do I use Q_OBJECT slots and signals with multiple inheritance?

I looked through the related questions and couldn't find anything that addresses exactly what I was talking about, so let me describe.
I have a class, let's say foo that needs to have its own slots and signals, but also needs to inherit from QXmlDefaultHandler (sounds rather odd, but I encountered this situation when trying to use QHttp to read a website directly into a QBuffer).
class foo: public QXmlDefaultHandler, public QObject
{
public:
foo();
~foo();
Q_OBJECT
public slots:
void bar();
}
This code, if accompanied by a cpp to connect bar to a signal somewhere else, will not compile. You'll get errors about some members of QObject not being a member of QXmlDefaultHandler. Additionally, you can't move Q_OBJECT or else you get vtable errors for not implementing some things (go on! try it!).
please see my answer for the (very simple) fix. I will entertain voting you as the accepted answer if I think you explain it better than I do.
edit: for you c++ and Qt vets, please post an answer if you can explain it better. i spent quite a bit of time looking this info up, so please help someone else if you can do better than me.
The documentation for moc states that in cases of multiple inheritance, the class providing QObject should appear first
If you are using multiple inheritance,
moc assumes that the first inherited
class is a subclass of QObject. Also,
be sure that only the first inherited
class is a QObject.
// correct
class SomeClass : public QObject, public OtherClass
{
...
};
Virtual inheritance with QObject is
not supported.
class foo: public QObject, public QXmlDefaultHandler
{
public:
foo();
~foo();
Q_OBJECT
public slots:
void bar();
}
As simple as it sounds, if you don't put QObject first in the inheritance list, this task is impossible. It's a limitation in Qt's meta object system. If you don't do this, the compiler will try to apply some members of QObject as part of QXmlDefaultHandler.

Qt signals & inheritance question

I am relatively new to programming with Qt and had a question. Short version:
How do I inherit signals defined in superclasses?
I am trying to subclass someone else's nicely made QTWidgets to change some of the default behavior:
//Plot3D is a QWidget that defines a signal "rotationChanged"
class matLinePlot : public QObject, public Plot3D {
Q_OBJECT;
//etc...
public:
//etc...
//Catch Plot3D's signal "rotationChanged" and do some magic with it:
void initPlot(){
QObject::connect(this, SIGNAL(rotationChanged( double , double , double )),
this, SLOT(myRotationChanged(double, double, double)));
}
};
The problem is in the QObject::connect line. What I would like to do is connect the rotationChanged SIGNAL (from qwt3D_plot.h) to a local function/SLOT - "myRotationChanged". However whenever I do this, at run time I get:
Object::connect: No such signal matLinePlot::rotationChanged(double, double, double)
in C:...\matrixVisualization.h. Of course, I know that rotationChanged isn't in matrixVisualization.h - it's in qwt_plot3D.h, but I thought that since I inherit from Plot3D everything should be fine. But, now that I think about it, since SIGNAL and SLOT are macros, I assume MOC doesn't know/care about inheritance.
Which leads me to my question - since MOC and SIGNALS / SLOTS don't seem to know about inheritance etc: how can I subclass a widget defined somewhere else and get access to the widget's signals?
I have a lot of examples of how to use encapsulation to accomplish something like this, but I'm afraid I don't understand how to do this with inheritance.
Sorry if this is a ridiculous question - I feel like I'm missing something obvious.
I guess the problem is the multiple inheritance:
class matLinePlot : public QObject, public Plot3D
...
I assume that Plot3D is a subclass of QObject? In this case, you should do
class matLinePlot : public Plot3D
...
instead.
SIGNAL(x) and SLOT(x) are macros that generate string literals. At runtime, slots and signals are matched up using string compares of those generated literals.
(I would have added a comment to mdec's comment, but I don't have enough rep)
I believe that will work if the Plot3D::rotationChanged signal is public or protected. Are you sure the signal is not private?
Edit:
Although I could not find a specific reference, I'll have to conclude that signals are always public. At least a test I did here seemed to indicate that I could connect to a signal even if it was declared in the private section of a class.
I also verified that a signal declared in QObject could be connected using a subclass of QObject in the connect statement so signals are definitely inheritable. As I see in other answers and comments here, the issue must be elsewhere.
Incorrect -> see comments.
I'm using Qtopia at Uni and I believe I recall someone saying something about spacing in the SIGNAL and SLOT parameters for connect.
Try using
QObject::connect(this, SIGNAL(rotationChanged(double,double,double)),
this, SLOT(myRotationChanged(double,double,double)));
I know it doesn't seem intuitive, as C++ isn't sensitive to whitespace, however I believe it has something to do with some of the magic that Qtopia/QT uses when connecting signals and slots. This may only apply to Qtopia, or I may have heard wrong, but give it a try. Additionally are the signals public or protected and have you included the appropriate header files?

Resources