I have a problem using
QJsonValue and
QJsonObject
even when I add QT+=core.
I am using QT 5.5
Does anyone knows what could be the problem.
Thanks in advance
Pro file:
QT += core gui webkit network
TEMPLATE = app
SOURCES += main.cpp \
apiservis.cpp
HEADERS += \
apiservis.h
QT = core
QT -= gui
QT += webkit
QT += webkit webkitwidgets
QT += network
TARGET = cpp
CONFIG += console
CONFIG -= app_bundle
TARGET = main
DISTFILES += \
API_kljuc.txt
And in the .h file I have:
#include <QCoreApplication>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string.h>
#include <locale>
#include <sstream>
#include <fstream>
#include <string>
#include <curl/curl.h>
#include <stdio.h>
#include <QHash>
#include <QVariantMap>
#include <QWebFrame>
#include <QWebView>
#include <QNetworkReply>
#include <QCoreApplication>
#include <QDebug>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include <QObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonObject>
But when I try to build it, error is: QJsonARRay:No such file or directory.
Related
I have a login page and a welcome page (which open if user can bypass the login). In my login page
there is a line edit for entering username. So, for holding the username I declared a global variable in
the login.h.
My login.h file:
#include <QSqlQuery>
#include <QGridLayout>
#include <QPushButton>
#include <QString>
#include <QLabel>
#include <QFrame>
#include <QSqlRecord>
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class login : public Qlogin
{
Q_OBJECT
public:
login(QWidget *parent = nullptr);
~login();
private:
Ui::login *ui;
QString userDat; ///global variable
};
#endif // MAINWINDOW_H
I hold the username from the line edit in login.cpp like this.
My login.cpp file:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlQueryModel>
#include <QSqlQuery>
#include <QGridLayout>
#include <QPushButton>
#include <QString>
#include <QLabel>
#include <QFrame>
#include <QSqlRecord>
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>
login::login(QWidget *parent)
: Qlogin(parent)
, ui(new Ui::login)
{
ui->setupUi(this);
userDat = ui-> login_lineEdit ->text();
}
login::~login()
{
delete ui;
}
I want to use the global variable userDat in my welcome.cpp file like this.
ui-> welcome_lineEdit->setText(userDat);
I've included all required header file in welcome.h and welcome.cpp. But it still says:
userDat is not declared in this scope.
please help
Update from comments:
#include <QSqlQuery>
#include <QGridLayout>
#include <QPushButton>
#include <QString>
#include <QLabel>
#include <QFrame>
#include <QSqlRecord>
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class UserData {
public:
static QString userName;
};
class login : public Qlogin
{
Q_OBJECT
public:
login(QWidget *parent = nullptr);
~login();
private:
Ui::login *ui;
};
#endif // MAINWINDOW_H
in login.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlQueryModel>
#include <QSqlQuery>
#include <QGridLayout>
#include <QPushButton>
#include <QString>
#include <QLabel>
#include <QFrame>
#include <QSqlRecord>
#include <QFileDialog>
#include <QPixmap>
#include <QMessageBox>
QString UserData::userName = "empty";
login::login(QWidget *parent)
: Qlogin(parent)
, ui(new Ui::login)
{
ui->setupUi(this);
UserData::userName = ui-> login_lineEdit ->text();
}
login::~login()
{
delete ui;
}
and somethere in another place:
ui-> welcome_lineEdit->setText(UserData::userName);
I am using a mini2440 board. I want to develop a gui for pwm that can increase and decrease the frequency of the signal. It has four buttons - start, stop, max and min - but pressing the max button makes no change in freq. By using the start and stop the gui program terminate but still pwm is on, I mean buzzer is on.
Here is the code
#include "hello.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
#include <qobject.h>
#include <fstream>
#include <linux/i2c-dev.h>
#include <string.h>
#include <stdio.h>
#include <linux/fs.h>
#include <termios.h> //Headers
#include <stdint.h>
#include <getopt.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#define PWM_IOCTL_SET_FREQ 1
#define PWM_IOCTL_STOP 0
int freq=1000;
int fd;
HelloForm::HelloForm( QWidget* parent, const char* name, WFlags fl)
:HelloBaseForm(parent, name, fl)
{
connect(PushButton33,SIGNAL(clicked()),this,SLOT(start()));
connect(PushButton30,SIGNAL(clicked()),this,SLOT(stop()));
connect(PushButton31,SIGNAL(clicked()),this,SLOT(plus()));
connect(PushButton32,SIGNAL(clicked()),this,SLOT(minus()));
}
HelloForm::~HelloForm()
{
}
// this is start button
void HelloForm::start()
{
int fd = open("/dev/pwm", 0);
if (fd < 0) {
status->setText("open pwm_buzzer device");
}
else {
status->setText("start");
}
ioctl(fd, PWM_IOCTL_SET_FREQ, freq);
pwm->setText(QString::number(freq));
//close(fd);
}
//stop button
void HelloForm::stop()
{
close(fd);
int fd=open("/dev/pwm",0); //File handler
ioctl(fd, PWM_IOCTL_STOP); // stop the ioctl
close(fd);
}
// increase the pwm
void HelloForm::plus()
{
if(freq<20000)
{
freq+=10;
ioctl(fd,PWM_IOCTL_SET_FREQ,freq); //freq set
pwm->setText(QString::number(freq));
}
}
void HelloForm::minus()
{
if(freq>11)
{
freq-=10;
ioctl(fd,PWM_IOCTL_SET_FREQ,freq);
pwm->setText(QString::number(freq));
}
}
I have a problem. I have QT 5.3.1 and Ubuntu 14.04.
For example:
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QPixmap>
#include <QImage>
#include <QComboBox>
#include <QFileDialog>
#include <QlineEdit>
#include <QLabel>
#include <QFile>
#include <QIODevice>
#include <QSlider>
#include <QMessageBox>
Works well.
The problem is the following line:
#include <QlineEdit>
Compilator return error: QlineEdit: No such file or directory.
How do I fix this?
There is no such class a QlineEdit. However, there is a QLineEdit class.
Note the capital 'L' in Line.
As you've tagged your question with 'Ubuntu' and you're using Linux, it's likely to be case-sensitive, so the capitalisation matters here.
I'm creating a sort of drawable object class for mesh data and i'm getting this linker error. This is also on top of another class that handles the drawing of the meshes that was used in one of the Qt tutorials. I'm also using a QGLWidget to be the surface i'm drawing to. Here's what the header file looks for the first class.
#ifndef GLOBJECT_H
#define GLOBJECT_H
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QVector3D>
#include <QVector2D>
#include <QDebug>
#include <QFile>
struct VertexData
{
QVector3D position;
QVector2D texCoord;
QVector3D normal;
};
class GLObject
{
public:
GLObject();
VertexData *data;
GLushort *indices;
GLuint vboIds[2];
int faceCount, vertCount;
bool generateFromPLY(QString filename);
};
#endif // GLOBJECT_H
Here's the header for the other class.
#ifndef GEOMETRYENGINE_H
#define GEOMETRYENGINE_H
#include <QObject>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QVector2D>
#include <QVector3D>
#include <QFile>
#include <QDebug>
#include <QVector>
#include <globject.h>
class GeometryEngine : public QObject, protected QOpenGLFunctions
{
Q_OBJECT
public:
GeometryEngine();
~GeometryEngine();
void init();
void drawGeometry(QOpenGLShaderProgram *program);
//void drawCubeGeometry(QOpenGLShaderProgram *program);
bool generateFromPly(QString filename);
QVector<GLObject> drawables;
int drawableId = 0;
};
#endif // GEOMETRYENGINE_H
G:\Dropbox\GLSLDemo\globject.cpp:60: error: 'glGenBuffers' was not declared in this scope
glGenBuffers(2, vboIds);
along with the same error for the other gl calls.
Initially I had all the code in GeometryEngine to begin with. I didn't have a scope issue then. initilizeOpenGLFunctions() is called in GeometryEngine's init() if that's relevant.
^
QT OpenGL is weird. I think the QOpenGLFunctions maintains a common context. Also i'm bad at C++ and used protected wrong.
I wrote a simple TCP/IP network applications (server and client). In the code of client app, I did like this and then build with 'g++ -o client client.cpp' under Linux.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char* argv[])
{
struct sockaddr_in server_addr;
struct hostent* host;
....
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(nPort);
server_addr.sin_addr = *((struct in_ddr*)host->h_addr); /*It complains as below while building*/
....
}
client.cpp: In function 'int main(int, char**)':
client.cpp:56: error: no match for 'operator=' in 'server_addr.sockaddr_in::sin_addr = *(in_ddr*)(* host->hostent::h_addr_list)'
/usr/include/netinet/in.h:138: note: candidates are: in_addr& in_addr::operator=(const in_addr&)
* Error code 1
clearmake: Error: Build script failed for "client"
what's going on with my implementaion?
You are trying to set an address list as a single address. You'll want to use brackets to refer to the address you want. host->h_addr_list[0]
At least that is what I am getting from your error.
Reference sources