I've written an application which sends a value (later this will be the value from QTextEdit) to an Arduino by clicking a button. I'm able to build it, but when I run the application, it crashes...
I can't seem to find the problem...
Thanks in advance!
main.cpp
#include "serialcommunication.h"
#include <QtGui>
#include <qextserialport.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
SerialCommunication w;
w.show();
return a.exec();
}
serialcommunication.h
#ifndef SERIALCOMMUNICATION_H
#define SERIALCOMMUNICATION_H
#include <QtGui>
#include "ui_serialcommunication.h"
#include <qextserialport.h>
class SerialCommunication : public QWidget
{
Q_OBJECT
public:
SerialCommunication();
~SerialCommunication();
QextSerialPort *port;
void init_port();
void transmitCmd(int value);
private slots:
void clickclick();
private:
Ui::SerialCommunicationClass ui;
QTextEdit *textedit;
QPushButton *pushbutton;
};
#endif // SERIALCOMMUNICATION_H
serialcommunication.cpp
<pre lang="c++">#include "serialcommunication.h"
SerialCommunication::SerialCommunication():QWidget()
{
ui.setupUi(this);
textedit = new QTextEdit;
pushbutton = new QPushButton("PUSHBUTTON");
init_port();
connect(pushbutton, SIGNAL(clicked()), this, SLOT(clickclick()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(textedit);
layout->addWidget(pushbutton);
setLayout(layout);
}
SerialCommunication::~SerialCommunication()
{
}
void SerialCommunication::clickclick()
{
transmitCmd(123);
}
void SerialCommunication::init_port()
{
port = new QextSerialPort("COM4");
port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
if(!port->isOpen())
{
QMessageBox::warning(this, "port error", "Impossible to open the port!");
}
else if(port->isOpen());
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
}
void SerialCommunication::transmitCmd(int value)
{
if(value < 0 || value >255)return;
char *buf;
*buf = value;
port->write(buf);
}
screenshot error
http://dl.dropbox.com/u/12844842/error.JPG[
^]