Im trying to load user32 in QT5 by doing:
#include <qlibrary.h>
#include <windows.h>
#include <lmcons.h>
#include <process.h>
#include <stdio.h>
#include <userenv.h>
#include <winuser.h>
QLibrary *lib = new QLibrary("user32");
QFunctionPointer p;
if(lib->load() && (p = lib->resolve("GetLastInputInfo"))) {
qDebug() << "Lib loaded";
} else {
qDebug() << "Lib could not load";
}
But keep getting output "Lib could not load"
Any ideas what I could be doing wrong?
Related
This is the second way I have rearranged this, and it is doing the same thing, so now I seek help. There are no errors being thrown, the slot just never does anything.
There are two other connections that are working between the same two cpps, and I decided to add this third one that the main window triggers, to the main window.
on_line_edit_returnPressed(), is printing hol_num and that is where it ends. ReadyHollander emits and HolPub never does anything. What am I doing wrong?
mainwindow cpp
#include "wheelscannerui.h"
#include "./ui_wheelscannerui.h"
gui_image_node *m_gui_image_node;
WheelScannerUI::WheelScannerUI(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::WheelScannerUI)
{
ui->setupUi(this);
connect(m_gui_image_node, &gui_image_node::ReadyImage, this, &WheelScannerUI::updateWheelImage);
connect(m_gui_image_node, &gui_image_node::OpenHollander, this, &WheelScannerUI::Open_No_ID);
connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub);
qDebug() << connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub);
ui->lineEdit->setVisible(false);
QMainWindow::showFullScreen();
}
WheelScannerUI::~WheelScannerUI()
{
delete ui;
}
void WheelScannerUI::Open_No_ID(QString qsteve)
{
ui->lineEdit->setVisible(true);
}
void WheelScannerUI::on_lineEdit_returnPressed()
{
QString hol_num = ui->lineEdit->text();
Q_EMIT ReadyHollander(hol_num);
ui->lineEdit->setVisible(false);
ui->lineEdit->clear();
qDebug() << hol_num;
}
main windows .h
#ifndef WHEELSCANNERUI_H
#define WHEELSCANNERUI_H
#include <QMainWindow>
#include <QtSql>
#include <QSqlQuery>
#include <QSqlDatabase>
#include <QSqlQueryModel>
#include "gui_image_node.h"
#include <QPixmap>
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Int64.h>
#include <sensor_msgs/image_encodings.h>
#include <nodelet/nodelet.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
#include <pluginlib/class_list_macros.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <iostream>
extern gui_image_node *m_gui_image_node;
QT_BEGIN_NAMESPACE
namespace Ui { class WheelScannerUI; }
QT_END_NAMESPACE
class WheelScannerUI : public QMainWindow
{
Q_OBJECT
public:
WheelScannerUI(QWidget *parent = nullptr);
~WheelScannerUI();
WheelScannerUI *m_WheelScannerUI;
void connectionClose()
{
db.close();
db.removeDatabase(QSqlDatabase::defaultConnection);
}
bool connectionOpen()
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("~/wheels.db");
if(!db.open())
{
qDebug()<<("Database failed to open");
return false;
}
else{
qDebug()<<("database connected");
return true;
}
}
public slots:
Q_SLOT void Open_No_ID(QString qsteve);
Q_SLOT void open_db_table(); //trigger with a ros callback?
signals:
Q_SIGNAL void ReadyHollander(QString);
private slots:
void on_lineEdit_returnPressed();
void on_Mode_Button_clicked();
private:
Ui::WheelScannerUI *ui;
QSqlDatabase db;
};
#endif // WHEELSCANNERUI_H
node cpp
#include "gui_image_node.h"
gui_image_node::gui_image_node()
{
}
bool gui_image_node::init(int argc, char** argv)
{
m_pThread = new QThread();
this->moveToThread(m_pThread);
connect(m_pThread, &QThread::started, this, &gui_image_node::run);
ros::init(argc, argv, "wheels_gui_image");
if ( ! ros::master::check() )
{
return false;
}
ros::start();
ros::Time::init();
ros::NodeHandle nh;
hollander_pub = nh.advertise<std_msgs::String>("/hollander_chat", 1);
hol_trigger = nh.subscribe("awaiting_hollander", 1, &gui_image_node::Hollander_Screen_trigger_callback, this);
m_pThread->start();
return true;
}
void gui_image_node::Hollander_Screen_trigger_callback(const std_msgs::String::ConstPtr& msg)
{
std::string steve = msg->data;
QString qsteve = QString::fromStdString(steve);
Q_EMIT OpenHollander(qsteve);
}
void gui_image_node::HolPub(QString hol_num)
{
qDebug() << "received number";
std::string hol_num_conv = hol_num.toUtf8().constData();
std_msgs::String msg;
msg.data = hol_num_conv;
hollander_pub.publish(msg);
}
nodes .h
#ifndef GUI_IMAGE_NODE_H
#define GUI_IMAGE_NODE_H
#include <ros/ros.h>
#include <nodelet/nodelet.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>
#include <std_msgs/String.h>
#include <QMainWindow>
#include <QObject>
#include <QSharedDataPointer>
#include <QWidget>
#include <QThread>
#include <string>
#include <QMutex>
#include <QDebug>
#include <QDialog>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <iostream>
class gui_image_node : public QThread
{
Q_OBJECT
public:
gui_image_node();
~gui_image_node();
bool init(int argc, char** argv);
void Hollander_Screen_trigger_callback(const std_msgs::String::ConstPtr& msg);
protected:
public slots:
Q_SLOT void run();
Q_SLOT void HolPub(QString hol_num);
signals:
Q_SIGNAL void OpenHollander(QString);
private:
ros::Publisher hollander_pub;
ros::Subscriber hol_trigger;
QThread * m_pThread;
};
#endif // GUI_IMAGE_NODE_H
OK, I figured it out, connect(this, &WheelScannerUI::ReadyHollander, m_gui_image_node, &gui_image_node::HolPub, Qt::Directconnection);
Since this is being triggered from another thread, Directconnection allows the thread it is being emitted from to trigger the slot in a different thread.
Problems not create Can Bus Device, create project Qt 5.10 why not create ??
package serialbus be connected. CAN be connected across USB. IIts so hard. My life its harded. I'm a national minority, I'm not as clever as white masters, please do not grieve for me.
can bus Device not working
file.pro
QT += core gui serialbus
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CAN_simple_experiment
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSerialBus>
#include <QCanBus>
#include <QCanBusDevice>
#include <QDebug>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
int i = 0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
// Create device.
QCanBusDevice *device =
QCanBus::instance()>createDevice("socketcan","vcan0");
if (device != nullptr){
qDebug() << "Created device, state is:" << device->state();
ui->textEdit->append("Created device, state is:"+ device->state());
} else {
qFatal("Unable to create CAN device.");
ui->textEdit->append("Unable to create CAN device.");
}
//Connect.
if(device->connectDevice()){
qDebug() << "Connected, state is:" << device->state();
ui->textEdit->append("Connected, state is:"+ device->state());
} else {
qDebug() << "Connect failed, error is:" << device->errorString();
ui->textEdit->append("Connect failed, error is:"+ device->errorString());
}
}
You need first to check SocketCAN interfaces that can be used check documentation.
QString errorString;
const QList<QCanBusDeviceInfo> devices = QCanBus::instance()->availableDevices(
QStringLiteral("socketcan"), &errorString);
if (!errorString.isEmpty())
qDebug() << errorString;
You can't create the device if the list is empty (watch the errorString);
// Create device.
if (devices.count())
QCanBusDevice *device =
QCanBus::instance()>createDevice("socketcan","vcan0");
There is no support of socketcan on Windows.
There are Linux specific calls inside socketcanbackend.cpp:
#include <linux/can/error.h>
#include <linux/can/raw.h>
#include <linux/sockios.h>
...
if (Q_UNLIKELY(ioctl(canSocket, SIOCGSTAMP, &timeStamp) < 0)) {
...
etc
I'm trying to use GLEW with QT in a QOpenGLWidget in Visual Studio.
Some details:
Visual Studio 2013
Glew 2.0.0 x64
QT 5.6.2 x64
I keep getting "Missing GL version" error when calling glewInit(). I've searched online a lot, and this problem seems to sometimes be caused by how the format is set (QSurfaceFormat), or how the functions create()/ makeCurrent() / doneCurrent() are used. But I can't seem to find a working solution. I'm still a bit confused about the whole QOpenGLContext thing also.
I manage to get the QOpenGLWidget work without GLEW, and using "old" gl functions (glBegin(), glEnd(), etc...). And I also get GLEW to work with GLFW3.
Is there something I seem to misunderstand in the code below?
My subclass of QOpenGLWidget
MyGLWidget.h
#pragma once
#include <QWidget>
#include "GL\glew.h"
#include <QOpenGLWidget>
#include <gl/GLU.h>
#include <gl/GL.h>
#include <iostream>
#include "qopenglcontext.h"
#include "loadShader.h"
class MyGLWidget : public QOpenGLWidget
{
public:
MyGLWidget(QWidget *parent = 0);
~MyGLWidget();
public:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
};
MyGLWidget.cpp
#include "MyGLWidget.h"
MyGLWidget::MyGLWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
QSurfaceFormat glformat;
glformat.setVersion(3, 2);
glformat.setOption(QSurfaceFormat::DeprecatedFunctions);
glformat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
glformat.setProfile(QSurfaceFormat::CompatibilityProfile);
QSurfaceFormat::setDefaultFormat(glformat);
this->setFormat(glformat);
create();
makeCurrent();
}
MyGLWidget::~MyGLWidget(){}
void MyGLWidget::initializeGL()
{
glewExperimental = TRUE;
GLenum err = glewInit();
if (GLEW_OK != err){
std::cout << "[Error] GLEW failed to initialize. " << (const char*)glewGetErrorString(err);
}
doneCurrent();
GLuint TextShader_ID = LoadShaders("Shaders/TextVertShader.vert", "Shaders/TextFragShader.frag");
}
void MyGLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void MyGLWidget::resizeGL(int w, int h)
{
//...
}
main.cpp
#include "OGLQT_test2.h"
#include <QtWidgets/QApplication>
#include "GL\glew.h"
#include <QOpenGLFunctions>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
OGLQT_test2 w;
w.show();
return a.exec();
}
OGLQT_test2.h
#pragma once
#include "GL\glew.h"
#include <QtWidgets/QMainWindow>
#include "ui_OGLQT_test2.h"
#include "qopenglcontext.h"
class OGLQT_test2 : public QMainWindow
{
Q_OBJECT
public:
OGLQT_test2(QWidget *parent = Q_NULLPTR);
private:
Ui::OGLQT_test2Class ui;
};
OGLQT_test2.cpp
#include "OGLQT_test2.h"
#include "MyGLWidget.h"
OGLQT_test2::OGLQT_test2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
MyGLWidget* glwidget = new MyGLWidget(this);
glwidget->setFixedHeight(400);
glwidget->setFixedWidth(500);
glwidget->move(50, 50);
glwidget->initializeGL();
glwidget->resizeGL(400,500);
glwidget->paintGL();
}
It seems that you cannot do this:
glformat.setVersion(x, y);
with GLEW. It works with QOpenGLFunctions, but apparently, it doesn't work with GLEW. You may not be able to do this, either:
glformat.setOption(QSurfaceFormat::DeprecatedFunctions);
glformat.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
glformat.setProfile(QSurfaceFormat::CompatibilityProfile);
Try removing the format.
Also, I think you're doing a little bit of a mess here:
glwidget->initializeGL();
glwidget->resizeGL(400,500);
glwidget->paintGL();
There is a simple way to do this, just do:
glwidget->resize(400,500);
glwidget->show();
resizeGL is an event called by resize. That goes the same for initializeGL() and paintGL() being called by show.
Another one is:
GLenum err = glewInit();
if (GLEW_OK != err){
std::cout << "[Error] GLEW failed to initialize. " << (const char*)glewGetErrorString(err);
}
doneCurrent();
Now why would you call doneCurrent here?
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 Client Server where client issues file operations to Server. Program runs perfectly when first read/delete command is issued. But when I issue second command read/delete, it exits with exit code 141. I determine reason to be SIGPIPE.But unable to resolve it. Can someone help me on this
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <sys/wait.h>
#include <mqueue.h>
#include <sys/stat.h>
//#include <limits.h>
#include "Functions.h"
#define PIPE_BUF 50000
#define MAXMESGDATA (PIPE_BUF -2*sizeof(long))
#define MESGHDRSIZE (sizeof(Message_buf) -MAXMESGDATA)
#define MAX_SIZE 512
pid_t serverPid;
pid_t clientPid;
void Server(int readfd,int writefd)
{
Message_buf server_MessageBuf;
int operationStatus = 0;
char inputFileName[MAXMESGDATA];
char operationToBePerformed[MAXMESGDATA];
char messageOnPIPE[MAXMESGDATA];
ssize_t length;
if((length=mesg_recv(readfd,&server_MessageBuf))==0)
{
printf("\n End of file while reading pathname");
}
strcpy(messageOnPIPE,server_MessageBuf.messageText);
printf("\n Server side Message on PIPE:%s \n ",messageOnPIPE);
operationStatus=interpretCommand(messageOnPIPE,operationToBePerformed,inputFileName);
if(strcasecmp(operationToBePerformed,"read")==0)
{
readFile(writefd,inputFileName);
//printf("\n Read %s ",inputFileName);
}
if(strcasecmp(operationToBePerformed,"delete")==0)
{
deleteFile(writefd,inputFileName);
}
}
int main()
{
int pipe1[2],pipe2[2];
pipe(pipe1);
pipe(pipe2);
//signal(SIGPIPE, SIG_IGN);
pid_t pid;
pid=fork();
serverPid=pid;
if(pid==0)
{
/*Call Server*/
close(pipe1[1]);
close(pipe2[0]);
Server(pipe1[0], pipe2[1]);
}
else
{
close(pipe1[0]);
close(pipe2[1]);
Client(pipe2[0],pipe1[1]);
}
return 0;
}
Your server is not running in a loop. It receives one message and then closes the pipe, so the second write fails and a SIGPIPE is sent to the client.