Hello everyone.
I'm not able to pass a struct as a reference to a function in another class in Qt.
I was able to do this on the site "https://ideone.com" as per the code below:
It worked
#include <iostream>
using namespace std;
struct stcTeste {
string vstrNome="Oiaaaa";
};
class clsRef{
public:
void fcDados (stcTeste &pstcTesteDados) {
stcTeste stcLocal;
stcLocal = pstcTesteDados;
cout << stcLocal.vstrNome << endl;
}
};
int main() {
clsRef *vobjRef = new clsRef();
stcTeste stcDados;
stcDados.vstrNome="Oi...";
vobjRef->fcDados(stcDados);
return 0;
}
#include <iostream>
using namespace std;
struct stcTeste {
string vstrNome="Oiaaaa";
};
class clsRef{
public:
void fcDados (stcTeste &pstcTesteDados) {
stcTeste stcLocal;
stcLocal = pstcTesteDados;
cout << stcLocal.vstrNome << endl;
}
};
int main() {
clsRef *vobjRef = new clsRef();
stcTeste stcDados;
stcDados.vstrNome="Oi...";
vobjRef->fcDados(stcDados);
return 0;
}
To copy to clipboard, switch view to plain text mode
Already in Qt the code below returns the following error:
Does not work !!!
//Arquivo : clsteste.h
{
Q_OBJECT
public:
explicit clsTeste
(QWidget *parent
= nullptr
);
struct stcInfoXml
{
};
void fcSalvarCadastroEmpresaDBXml
(QString &pstrCadEmpresa, stcInfoXml
&pstcInfoXmlDados
);
};
//Arquivo : clsteste.cpp
#include "clsteste.h"
void clsTeste
::fcSalvarCadastroEmpresaDBXml(QString &pstrCadEmpresa, stcInfoXml
&pstcInfoXmlDados
) {
stcInfoXml vstcLocal;
vstrLocal = pstrCadEmpresa;
vstcLocal = pstcInfoXmlDados;
}
//Arquivo : frmMainWindow.h
#include <clsteste.h>
Public:
typedef struct stcInfo
{
}stcInfoDados;
Private:
void fcMontarDadosXml();
//Arquivo : frmMainWindow.cpp
#include "frmMainWindow.h"
clsTeste *vobjTesteDBXml = new clsTeste();
vobjTesteDBXml->fcSalvarCadastroEmpresaDBXml(vpTeste, stcInfoDados);
//Arquivo : clsteste.h
class clsTeste : public QWidget
{
Q_OBJECT
public:
explicit clsTeste(QWidget *parent = nullptr);
struct stcInfoXml
{
QString vstrNome = "Oiaaaa";
};
void fcSalvarCadastroEmpresaDBXml(QString &pstrCadEmpresa, stcInfoXml &pstcInfoXmlDados);
};
//Arquivo : clsteste.cpp
#include "clsteste.h"
void clsTeste::fcSalvarCadastroEmpresaDBXml(QString &pstrCadEmpresa, stcInfoXml &pstcInfoXmlDados)
{
QString vstrLocal;
stcInfoXml vstcLocal;
vstrLocal = pstrCadEmpresa;
vstcLocal = pstcInfoXmlDados;
}
//Arquivo : frmMainWindow.h
#include <clsteste.h>
Public:
typedef struct stcInfo
{
QString vstrNome = "Oiaaaa";
}stcInfoDados;
Private:
void fcMontarDadosXml();
//Arquivo : frmMainWindow.cpp
#include "frmMainWindow.h"
QString vpTeste = "Oiaaa";
clsTeste *vobjTesteDBXml = new clsTeste();
vobjTesteDBXml->fcSalvarCadastroEmpresaDBXml(vpTeste, stcInfoDados);
To copy to clipboard, switch view to plain text mode
usr/include/libdrm -I. -I../../5.10.1/gcc_64/mkspecs/linux-g++ -o frmMainWindow.o ../RWCXML/frmMainWindow.cpp
//../RWCXML/frmMainWindow.cpp: In member function ‘void clsMainWindow::fcMontarDadosXml()’:
//../RWCXML/frmMainWindow.cpp:390:75: error: expected primary-expression before ‘)’ token
// vobjTesteDBXml->fcSalvarCadastroEmpresaDBXml(vpTeste, stcInfoDados);
^
Makefile:1363: recipe for target 'frmMainWindow.o' failed
make: *** [frmMainWindow.o] Error 1
10:57:58: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project RWCXML (kit: Desktop Qt 5.10.1 GCC 64bit)
When executing step "Make"
usr/include/libdrm -I. -I../../5.10.1/gcc_64/mkspecs/linux-g++ -o frmMainWindow.o ../RWCXML/frmMainWindow.cpp
//../RWCXML/frmMainWindow.cpp: In member function ‘void clsMainWindow::fcMontarDadosXml()’:
//../RWCXML/frmMainWindow.cpp:390:75: error: expected primary-expression before ‘)’ token
// vobjTesteDBXml->fcSalvarCadastroEmpresaDBXml(vpTeste, stcInfoDados);
^
Makefile:1363: recipe for target 'frmMainWindow.o' failed
make: *** [frmMainWindow.o] Error 1
10:57:58: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project RWCXML (kit: Desktop Qt 5.10.1 GCC 64bit)
When executing step "Make"
To copy to clipboard, switch view to plain text mode
Can anybody help me ?
Thanks in advance...
Bookmarks