Qt not recognising declared class - qt

I use Qt 4.6.3 to write application for FriendlyARM. I am trying to pass 2 pointers (pointing to classes axesParam1 and mainWin) to current class localTime but get these errors :
localtime.h:17: error: 'axesParam1' has not been declared
localtime.h:18: error: 'mainWin' has not been declared
localtime.h:26: error: ISO C++ forbids declaration of 'axesParam1' with no type
localtime.h:26: error: expected ';' before '*' token
localtime.h:27: error: ISO C++ forbids declaration of 'mainWin' with no type
localtime.h:27: error: expected ';' before '*' token
In file included from trackinputstatus.h:5,
from trackinput.h:5,
from mainwin.h:8,
from geoparam.h:5,
from axesparam3.h:5,
from axesparam2.h:5,
from axesparam1.h:5,
from main.cpp:14:
trackparamstatus.h:16: error: 'mainWin' has not been declared
trackparamstatus.h:24: error: ISO C++ forbids declaration of 'mainWin' with no type
trackparamstatus.h:24: error: expected ';' before '*' token
main.cpp: In function 'int main(int, char**)':
main.cpp:52: error: no matching function for call to 'localTime::setChildren(axesParam1*)'
localtime.h:17: note: candidates are: void localTime::setChildren(int*)
main.cpp:61: error: no matching function for call to 'localTime::setHome(mainWin*)'
localtime.h:18: note: candidates are: void localTime::setHome(int*)
main.cpp:62: error: no matching function for call to 'trackParamStatus::setHome(mainWin*)'
trackparamstatus.h:16: note: candidates are: void trackParamStatus::setHome(int*)
I did not declared setChildern to accept int* as an argument so why is it insisting on int*?
I have included the header file localtime.h
#ifndef LOCALTIME_H
#define LOCALTIME_H
#include &ltQWidget>
#include "axesparam1.h"
#include "mainwin.h"
namespace Ui {
class localTime;
}
class localTime : public QWidget {
Q_OBJECT
public:
localTime(QWidget *parent = 0);
~localTime();
void setChildren(axesParam1 *);
void setHome(mainWin *);
protected:
void changeEvent(QEvent *e);
private:
Ui::localTime *ui;
axesParam1 *P1;
mainWin *w;
};
#endif // LOCALTIME_H

You look too far down. Before you look at setChildern you should look into axesparam1 and/or mainwin.
localtime.h:17: error: 'axesParam1' has not been declared
localtime.h:18: error: 'mainWin' has not been declared
You have some syntex error earlier. setChildern is only some follow-up error.

Related

QML, How to correctly expose c++ type - got "undefined symbol"

I have a class that returns a list of custom objescts, to view in qml
#include <QObject>
#include "networkinterface.h"
class Network : public QObject {
Q_OBJECT
public:
explicit Network(QObject *parent = 0);
Q_INVOKABLE QList<NetworkInterface> getNetworkAdaptors();
private:
QList<NetworkInterface> networkAdaptors; };
At main.qml i call this method as
model: network.getNetworkAdaptors()
It all was working when NetworkInterface was a struct, but when i converted it to a class, can't make it work.
Class NetworkInterface is inherited from QObject and got properties
class NetworkInterface : public QObject
{
Q_OBJECT
public:
NetworkInterface();
QString name;
QString description;
const QString &getName() const;
void setName(const QString &newName);
const QString &getDescription() const;
void setDescription(const QString &newDescription);
...
private:
Q_PROPERTY(QString name READ getName CONSTANT)
Q_PROPERTY(QString description READ getDescription CONSTANT)
};
So the error i got is :
main.cpp.o:-1: error: Undefined symbols for architecture x86_64:
"NetworkInterface::NetworkInterface()", referenced from:
QtPrivate::QMetaTypeForType<NetworkInterface>::getDefaultCtr()::'lambda'(QtPrivate::QMetaTypeInterface const*, void*)::operator()(QtPrivate::QMetaTypeInterface const*, void*) const in mocs_compilation.cpp.o
Network::getNetworkAdaptors() in network.cpp.o
_main in main.cpp.o
I suspect it is wrong type expose, as with sctruct it was working fine, how to do that correctly?
UPD: in NetworkInterface i have following constructors:
NetworkInterface();
NetworkInterface(const NetworkInterface &obj);
NetworkInterface & operator=( const NetworkInterface & obj);
Without them i can't push_back(networkInterface) to the list of interfaces, as it requires copy constructor. Also list of pointers won't work for qml as a model, it must be exactly objects list.
When i copy all code in NetworkInterface and leave only above constructors, it is minimal code that gives a error.
Default constructor was missing, adding
NetworkInterface::NetworkInterface(QObject *parent) : QObject(parent)
{
}
Resoled a problem

Syntax error: missing ';' before '*' when creating a pointer object of a user defined abstract class

I am trying to create pointer objects for my defined class 'FeralScene'
But i keep getting this error "Syntax error: missing ';' before '*'"
i dont know wats wrong with my code... could smone pls help me out?
/***********************************************************************
2D Engine Header File
File Name: FeralFramework
File Desc: Header to the Main Framework file
************************************************************************/
#ifndef FERALFRAMEWORK_H
#define FERALFRAMEWORK_H
#pragma once
#include<Windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include<string>
#include <dinput.h>
#include"FeralScene.h"
#include"GraphicDevice.h"
#include "Stdinc.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
class FeralFramework
{
public:
LPDIRECTINPUT8 inputDevice;
LPDIRECT3DDEVICE9 Device;
HWND WindowHandler;
HINSTANCE Instance;
FeralScene *CurrentScene,*PrevScene; // error occurs here
GraphicDevice graphicDevice;
static HWND StaticWindowHandle;
static IDirect3DDevice9 *GraphDevice;
int ScreenHeight;
int ScreenWidth;
bool IsFullScreen;
bool WindowCreation();
bool InitDirectx();
void MessageLoop();
void SetLighting();
void UpdateDrawLoopCallFunction();
void InitFrameWork();
void Render();
void initializeDirectInput();
//void Camera(int mx, int my);
void SceneSwitcher(FeralScene *SCENETOSWITCHTO);
// the FeralScene identifier error occurs here
FeralFramework();
FeralFramework(HINSTANCE Instance,int ScreenHeight,int ScreenWidth ,bool IsFullScreen,FeralScene *SentSceneObject );
// the FeralScene identifier error occurs here
FeralFramework(HINSTANCE Instance,FeralScene *SentSceneObject);
// the FeralScene identifier error occurs here
};
inline LRESULT CALLBACK WndProc(HWND WindowHandler,UINT Msg,WPARAM wparam,LPARAM lparam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return true;
default:
return DefWindowProc(WindowHandler,Msg,wparam,lparam);
}
}
#endif
And here is a list of the errors that pop up when i try to compile it
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C2143: syntax error : missing ';' before '*'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(55): error C2061: syntax error : identifier 'FeralScene'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(58): error C2061: syntax error : identifier 'FeralScene'
1>c:\users\sys\documents\visual studio 2010\projects\feralengine\feralengine\feralframework.h(59): error C2061: syntax error : identifier 'FeralScene'
What am i missing ? Any help will be appreciated :(
And here is the code for FeralScene
/***********************************************************************
2D Engine Header File
File Name: FeralScene
File Desc: Header to the FeralScene file
************************************************************************/
#pragma once
#include<d3dx9.h>
#pragma once
#include<Windows.h>
#include<d3d9.h>
#include<d3dx9.h>
#include"GraphicDevice.h"
#include "FeralFramework.h"
//#include "Vector.h"
class FeralScene
{
public:
HWND WindowHandler;
IDirect3DDevice9 *Device;
int BackBufferHeight;
int BackBufferWidth;
bool IsFullScreen,HasLoadedResources,HasUnloadedResources;
virtual void Initialize(FeralScene *SentSceneObject) =0;
virtual void Load(GraphicDevice graphicDevice) =0;
virtual void Update(GraphicDevice graphicDevice) =0;
virtual void Draw(GraphicDevice graphicDevice) =0;
virtual void Unload() =0;
virtual void Lighting()=0;
virtual void LoadAnim()=0;
virtual void UnloadAnim()=0;
};
You are including FeralFrameWork.h in feralscene.h. Which doesnt know of FeralScene.h yet. You can crete a forward decleration in FeralFramework.h. Also I suggest using proper macros in FeralScene.h also to avoid multiple decelerations.
Since you are using pointer types in header forward decleration will resolve the issue.
// this should be before the class FeralFramework
class FeralScene;

Qt: Iterators and OBject: copy constructor error

In class called UserForms, I define a list (QList) or SqlQueryModel objects (subclass of QSqlQueryModel), as in this Qt tutorial.
In userforms.h:
QList<SqlQueryModel> userModels;
Then in my main code, I want to iterate over userModel, so I tried both of the following:
UserForm selectedUF = formSelectorDiag.getSelectedUF();
QList<SqlQueryModel>::iterator umIt;
for(umIt = selectedUF.userModels.begin(); umIt != selectedUF.userModels.end(); umIt++){
SqlQueryModel model = *umIt;
// Additional code removed since error happens on previous line.
}
And:
QListIterator<SqlQueryModel> umIt(selectedUF.userModels);
With both, I get a "copy constructor" error, although, I don't copy the constructor (or I don't think I do). Cf sqlquerymodel.h:
class SqlQueryModel : public QSqlQueryModel
{
Q_OBJECT
void generateRoleNames();
public:
explicit SqlQueryModel(QObject *parent = 0);
void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
void setQuery(const QSqlQuery &query);
QVariant data(const QModelIndex &index, int role) const;
QHash<QString, QVariant> bindings; // Not used yet. Will be replaced by Binding class.
QString modelName;
QString query;
signals:
void bindedValueChanged();
public slots:
void search(QString);
void reset();
void updateBindings();
};
Here's the full exact error:
In file included from ..\..\..\..\Qt\4.8.4\include\QtSql/qsqlquerymodel.h:1:0,
from ..\..\..\..\Qt\4.8.4\include\QtSql/QSqlQueryModel:1,
from ..\SSL_Tool\/sqlquerymodel.h:4,
from ..\SSL_Tool\main.cpp:12:
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/kernel/qabstractitemmodel.h: In copy constructor 'QSqlQueryModel::QSqlQueryModel(const QSqlQueryModel&)':
..\..\..\..\Qt\4.8.4\include\QtSql/../../src/sql/models/qsqlquerymodel.h:37:20: instantiated from 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = SqlQueryModel]'
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:689:9: instantiated from 'void QList<T>::detach_helper(int) [with T = SqlQueryModel]'
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:703:5: instantiated from 'void QList<T>::detach_helper() [with T = SqlQueryModel]'
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:100:80: instantiated from 'QList<T>::QList(const QList<T>&) [with T = SqlQueryModel]'
..\SSL_Tool\/userform.h:17:7: instantiated from here
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/kernel/qabstractitemmodel.h:338:5: error: 'QAbstractTableModel::QAbstractTableModel(const QAbstractTableModel&)' is private
..\..\..\..\Qt\4.8.4\include\QtSql/../../src/sql/models/qsqlquerymodel.h:37:20: error: within this context
In file included from ..\SSL_Tool\main.cpp:12:0:
..\SSL_Tool\/sqlquerymodel.h: In copy constructor 'SqlQueryModel::SqlQueryModel(const SqlQueryModel&)':
..\SSL_Tool\/sqlquerymodel.h:14:7: note: synthesized method 'QSqlQueryModel::QSqlQueryModel(const QSqlQueryModel&)' first required here
In file included from ..\..\..\..\Qt\4.8.4\include/QtCore/qlist.h:1:0,
from ..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/kernel/qobject.h:28,
from ..\..\..\..\Qt\4.8.4\include/QtCore/qobject.h:1,
from ..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/kernel/qcoreapplication.h:23,
from ..\..\..\..\Qt\4.8.4\include/QtCore/qcoreapplication.h:1,
from ..\..\..\..\Qt\4.8.4\include\QtGui/../../src/gui/kernel/qapplication.h:23,
from ..\..\..\..\Qt\4.8.4\include\QtGui/qapplication.h:1,
from ..\..\..\..\Qt\4.8.4\include\QtGui/QApplication:1,
from ..\SSL_Tool\main.cpp:1:
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = SqlQueryModel]':
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:689:9: instantiated from 'void QList<T>::detach_helper(int) [with T = SqlQueryModel]'
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:703:5: instantiated from 'void QList<T>::detach_helper() [with T = SqlQueryModel]'
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:100:80: instantiated from 'QList<T>::QList(const QList<T>&) [with T = SqlQueryModel]'
..\SSL_Tool\/userform.h:17:7: instantiated from here
..\..\..\..\Qt\4.8.4\include/QtCore/../../src/corelib/tools/qlist.h:377:17: note: synthesized method 'SqlQueryModel::SqlQueryModel(const SqlQueryModel&)' first required here
mingw32-make[1]: Leaving directory `C:/Users/XXX/build-SSL_Tool-Desktop-Debug'
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
Any idea why?
QSqlQueryModel (and all other QObject-derived objects) can't be copied using copy constructor. QList requires its element type to have copy constructor. So, you need to use QList<SqlQueryModel*> instead of QList<SqlQueryModel>. You should create and delete your model objects manually using new and delete.

Qt matching signal with custom slot

I'm trying to use a QAction (QMenu member entry) to open a new window. Precisely: I want actionAbout signal predefined activated to match MainWindow custom slot open AboutWindow - and that's what I've got trouble with.
I know that I can use either the connect Qt function manually inside the source main_window.cpp file or just click it up in the Qt Creator, but my custom slot doesn't show up so I cannot select it. Maybe my slot function declaration is wrong (invalid parameters) and that's why QtCreator doesn't allow me to choose my custom slot in the GUI signals & slots. Could anyone point me what should I do to make QtCreator display my custom slot in the dropdown and how should the connect function call look like?
This is my main_window.h file content:
#include
#include "about_window.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void openAboutWindow();
private:
Ui::MainWindow *ui;
Ui::AboutWindow *aboutWindow;
};
And this is main_window.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(actionAbout, SIGNAL(activated()), this, SLOT(openAboutWindow(this));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openAboutWindow(QWidget *parent)
{
aboutWindow = new Ui::AboutWindow(parent); // Be sure to destroy you window somewhere
aboutWindow->show();
}
The compiler shouts about both constructor and openAbutWindow:
../Application/main_window.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’:
../Application/main_window.cpp:9:13: error: ‘actionAbout’ was not declared in this scope
../Application/main_window.cpp:9:80: error: expected ‘)’ before ‘;’ token
../Application/main_window.cpp: In member function ‘void MainWindow::openAboutWindow(QWidget*)’:
../Application/main_window.cpp:19:44: error: invalid use of incomplete type ‘struct Ui::AboutWindow’
../Application/about_window.h:7:11: error: forward declaration of ‘struct Ui::AboutWindow’
../Application/main_window.cpp:20:15: error: invalid use of incomplete type ‘struct Ui::AboutWindow’
../Application/about_window.h:7:11: error: forward declaration of ‘struct Ui::AboutWindow’
../Application/main_window.cpp:9:13: error: ‘actionAbout’ was not declared in this scope
The error message says it all, where is the QAction defined? Should it be ui->actionAbout?
connect(actionAbout, SIGNAL(activated()), this, SLOT(openAboutWindow(this));
openAboutWindow() does not take any arguments, and regardless this is an instance not a type.

QT signals and slots unexpected Error

This is driving me insane....it was working earlier, but not it doesn't work. I have defined Q_SLOTS and Q_SIGNALS, and I was trying to connect them. It was working to an extent...and then all of a sudden everything stopped working, and now I am getting errors. My code is the following:
ControllerLogic.h
#ifndef CONTROLLERLOGIC_H
#define CONTROLLERLOGIC_H
#include "initdataaccess.h"
#include "mainframe.h"
#include <QtGui>
#include "initializationdatastructure.h"
/** This is a controller class; refering to the model-view-controller
* architecture.
*/
class ControllerLogic : public QObject
{
Q_OBJECT
public:
ControllerLogic(InitDataAccess *initDataAccess, MainFrame *mainFrame);
Q_SIGNALS:
void Signal();
private:
void setMainFrame(MainFrame mainFrame);
public Q_SLOTS:
void receive();
};
#endif // CONTROLLERLOGIC_H
ControllerLogic.cpp
#include "controllerlogic.h"
#include "licensedataaccess.h"
#include <qobjectdefs.h>
// obsolete...may be used later
ControllerLogic::ControllerLogic(InitDataAccess *initDataAccess, MainFrame *mainFrame)
{
connect(this, SIGNAL(signal()), mainFrame, SLOT(PrintTestSlot()));
}
void ControllerLogic::receive(){
qDebug()<<"RECEIVE";
}
void ControllerLogic::Signal(){
qDebug()<<"SIGNAL";
}
ERROR
moc_controllerlogic.obj:-1: error: LNK2005: "protected: void __thiscall ControllerLogic::Signal(void)" (?Signal#ControllerLogic##IAEXXZ) already defined in controllerlogic.obj
release\TSLSuite.exe:-1: error: LNK1169: one or more multiply defined symbols found
I also tried to define the signal as follows:
public:
Q_SIGNAL void Signal();
but I get the same error.
What is going on?
Please Help!
Thanks!
The problem is that you're trying to define a function called Signal()
Qt generates the body of the "signal" functions for you, and if you try to create your own definition, you will get the error that you're describing.
(As a side note, your connect statement appears to be broken s/signal/Signal/)

Resources