port linux app to win (runtime error)
hi,
does anybody know which are the steps to port my linux code to win. i change the includepath and lib values in my .pro file. compiling works fine but when i start my application i get an runtime error. have a qwtPlot object that get the data to plot by a Qthread. in linux all work fine. hope somebody can help me!!!
i use qt-4.5 and qwt-5.1 (also with qwt-5.2 i have the same problem)
thanks in advance
Re: port linux app to win (runtime error)
It's impossible to help without more information. Get a debugger and find out what code causes the crash.
Re: port linux app to win (runtime error)
I have done some tests. I get the runtime error when I instantiate the qwtPlot object in main.
nodeplot.h
Code:
#include "qwt_scale_widget.h"
#include "qwt_legend.h"
#include "qwt_legend_item.h"
#include "qwt_plot_canvas.h"
#include "qwt_plot_grid.h"
#include "qwt_plot.h"
#include <stdio.h>
#include <iostream>
#include<string.h>
#include <QString>
#include <QTcpSocket>
#include <QtNetwork>
#include <QMutex>
#include <QSemaphore>
Q_OBJECT
public:
/* constructor */
NodePlot
(QWidget *parent ,
int portnumber ,
char* hostname,
int node_id
);
{ return data.curve; }
int getHistory(){ return this->HISTORY; }
void set_params();
struct
{
double* data;
} data;
unsigned int ts; // timestamp
char pack_str[40]; // package storage
char hostname[30];
int portnumber; // portnumber of data communication with the server
double* timeData; // contains the values of the x-axis
int node_id; // id of sender node
unsigned char val; // utility var to control package ssequence in control_sequence function
int dataCount; // take trace of the amount of points to plot
QMutex mutex;
// mutex to handle array of data to plot
protected:
private:
int HISTORY;
int YMAX;
int YMIN;
char xTitle[30];
char yTitle[30];
};
#endif // NODEPLOT_H
nodeplot.cpp
Code:
#include "nodeplot.h"
using namespace std;
{
public:
{
#if QT_VERSION >= 0x040000
//setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
}
void setColor
(const QColor &color
) {
#if QT_VERSION >= 0x040000
c.setAlpha(150);
setPen(c);
//setBrush(c);
#else
setPen(color);
setBrush
(QBrush(color, Qt
::Dense4Pattern));
#endif
}
};
/*
class to set eventually the x-axis to time scale
*/
{
public:
TimeScaleDraw
(const QTime &base
): baseTime(base)
{
}
virtual QwtText label
(double v
) const {
QTime upTime
= baseTime.
addSecs((int)v
);
return upTime.toString();
}
private:
};
NodePlot
::NodePlot(QWidget *parent,
int portnumber,
char *hostname,
int node_id
): dataCount(0)
{
this->HISTORY=60;
set_params();
this->data.data=(double*)malloc(HISTORY*sizeof(double));
this->timeData=(double*)malloc(HISTORY*sizeof(double));
setAutoReplot(false);
/*
setting the vars for the tcp connection
*/
strcpy(this->hostname,hostname);
this->portnumber=portnumber;
this->node_id= node_id;
this->val=0;
plotLayout()->setAlignCanvasToScales(true);
/* set the x/y axis */
//setAxisTitle(QwtPlot::xBottom, " System Uptime [h:m:s]");
//setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(cpuStat.upTime()));
setAxisTitle
(QwtPlot::xBottom, xTitle
);
setAxisScale
(QwtPlot::xBottom,
-HISTORY,
0);
setAxisLabelRotation
(QwtPlot::xBottom,
-50.0);
setAxisLabelAlignment
(QwtPlot::xBottom, Qt
::AlignLeft | Qt
::AlignBottom);
/*
set the visual aspect of timestamp axis
*/
scaleWidget->setMinBorderDist(0, fmh / 2);
/* y-axis settings */
setAxisTitle
(QwtPlot::yLeft, yTitle
);
setAxisScale
(QwtPlot::yLeft, YMIN, YMAX
);
/*set the canvas background color*/
/*
draw a grid into canvas
*/
grid
->setMajPen
(QPen(Qt
::white,
0, Qt
::DotLine));
grid->attach(this);
/* curve to plot*/
NodeCurve *curve;
QPen pen
(Qt
::green);
//curve color pen.setWidth(1);
curve = new NodeCurve("Node curve");
//curve->setColor(Qt::green);
curve->setPen(pen);
curve->attach(this);
data.curve = curve;
/*
init x-axis scale
*/
for ( int i = 0; i < HISTORY; i++ )
timeData[HISTORY - 1 - i] = i - HISTORY + 1;
//(void)startTimer(50); // every 50 -millisecond
}
/*
timer event function: should be called every 50ms ( 20 hz refresh frequency)
*/
{
mutex.lock();
replot();
mutex.unlock();
}
void NodePlot::set_params(){
char str[100];
char str2[100];
char str3[100];
FILE* file_conf=fopen(".\\Win_QT\\config_canvas.txt","r");
while(!feof(file_conf)){
fgets(str,100,file_conf);
sscanf(str,"%s%s",str2,str3);
if(str[0]== '#') continue;
if(strcmp(str2,"HISTORY") == 0){
this->HISTORY=atoi(str3);
}
else if(strcmp(str2,"YMAX") == 0){
this->YMAX=atoi(str3);
}
else if(strcmp(str2,"YMIN") == 0){
this->YMIN=atoi(str3);
}
else if(strcmp(str2,"XTITLE") == 0){
strcpy(this->xTitle,str3);
}
else if(strcmp(str2,"YTITLE") == 0){
strcpy(this->yTitle,str3);
}
}
fclose(file_conf);
}
main.cpp
Code:
#include"nodeplot.h"
#include<stdio.h>
#include<stdlib.h>
#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>
int main(int argc, char* argv[]){
#if QT_VERSION >= 0x040000
vBox.setWindowTitle("Sensor Plot");
#else
vBox.setCaption("Sensor Plot");
#endif
NodePlot plot(&vBox,5000,"localhost",2);
layout->addWidget(&plot);
#if QT_VERSION < 0x040000
a.setMainWidget(&vBox);
#endif
vBox.resize(600,400);
vBox.show();
return a.exec();
}
.pro file
Code:
QT += network
HEADERS += nodeplot.h
SOURCES += nodeplot.cpp \
main.cpp
OTHER_FILES += config_canvas.txt
INCLUDEPATH += C:\Qt\2009.03\qt\qwt-5.2.0\src
LIBS += C:\Qt\2009.03\qt\qwt-5.2.0\lib\qwt5.dll
Re: port linux app to win (runtime error)
I had the same probleam yesterday, with both dll and static lib.
I didn't found a real solution but a simple workaround: recompile qwt disabling the CONFIG += QwtDll in qwtconfig.pri (it is line 78 in 5.2, don't know in 5.1)
In this manner you won't have the dll and you have to use the static lib, but at least you won't get the runtime error.