PDA

View Full Version : Transfer of a QByteArray to main.cpp



dolin93
1st January 2015, 21:06
Hallo,
with the attached program I can get a csv file from Yahoo Finance and store it in a QByteArray. But till now I didn`t succeed in transmitting the QByteArray or a QVector from filedownloader.cpp to main.cpp. I have already in vain tried many proceedings. Has anybody an idea how to overcome these difficulties?

anda_skoa
1st January 2015, 21:34
You are calling your data transfer function transmit() right after creating the downloader object.
There has been no time to actually get the data yet, the QNetworkAccessManager get() request is processed once the application has started event processing, i.e. when app.exec() is being called.

You already have a signal that is emitted when you've received the data.
Connect to that.

Cheers,
_

dolin93
2nd January 2015, 15:06
Thanks for Your help!
After insertion of
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(transmit(QList<QByteArray>)));
I got the massage
Object::connect: No such slot FileDownloader::transmit(QList<QByteArray>) and unfortunately there was no improvement.

A happy new year!

anda_skoa
2nd January 2015, 16:11
Why on earth did you even try that?
What could that possibly improve?

Just because some random code compiles doesn't mean it will do anything useful and even less often mean it will do what you need.

Take a step back and think about what you actually need.
And then come back and ask for that.

Cheers,
_

dolin93
3rd January 2015, 21:17
Thanks for Your help!
With PHP it is not difficult to get csv files from Yahoo Finance, use them for simple calculations and display the results in tables.
But with Qt/C++ I`d be more flexible and could even graphically display results and charts. Therefore I tried to get the csv files also with Qt/C++ and transfer the data to main.cpp or another source file where I could use them.

Cheers

wysota
3rd January 2015, 21:43
I don't think you understood what anda_skoa means. Please explain what you though this:


connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(transmit(QList<QByteArray>)));
would do and how you think it would solve your problem. Then take a piece of paper, a pencil and write down a step-by-step algorithm that achieves what you want. Then we will help you "translate" it to C++. Remember you are dealing with an asynchronous system.

dolin93
7th January 2015, 21:50
Thanks for Your answer!
Only after failure with
connect(SIGNAL(finished(QNetworkReply*)),
SLOT(transmit(QList<QByteArray>))); I tried the above mentioned Qt Code
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(transmit(QList<QByteArray>)));.
Now I use a class PrCalClass for calculations and call this class in filedownloader.cpp through
PrCalClass demo(m_DownloadedData);
demo.PrintM();. For the drawing of charts and results I`ll use another class.
But nevertheless I`d be very pleased if You showed me how one can bring the QByteArray m_DownloadedData into main.cpp.

anda_skoa
7th January 2015, 22:53
But nevertheless I`d be very pleased if You showed me how one can bring the QByteArray m_DownloadedData into main.cpp.

You have to understand that, for the rest of us, this goal does not make any sense.

Once the linker has linked all object code into the executable, there is no distinction anymore which source file the code came from.

You could just put the code of your file downloader class into main.cpp, remove the now unnecessary header and source file and still have the same program.
That would not change anything your program is doing, it would just increase the length of the now only cpp file.

Cheers,
_

dolin93
13th January 2015, 23:08
Thank You for Your answer!
Unfortunately I didn`t succeed in bringing downloaded data to the class mainWidget for drawing.

jefftee
14th January 2015, 02:23
I downloaded your zip file that contains your project. You are trying to fit a square peg into a round hole... :) You are dead set on getting a QByteArray back into your main routine, but here is the problem with your design.

You instantiate FileDownloader in your main() routine, which creates your QNetworkAccessManager, does the get request for your URL, etc. The signals for the get request won't actually be executed until your main routine runs the following code:


return a.exec();

This is because there is no message loop running yet, so no signals will be dispatched. What you should be doing, is doing all of your processing in your FileDownloader class and forget about trying to get the result into your main() routine.

Once your download completes in FileDownloader::fileDownloaded, what do you want to do next? Write new methods for FileDownloader to process the results of the download or use signals/slots to process the result, for example:


void FileDownloader::fileDownloaded(QNetworkReply* reply)
{
m_DownloadedData = reply->readAll();
// do all of your processing of the result here or add a new method, emit a signal, or call another method in FileDownloader, etc.
return;
}


Hope that helps.

anda_skoa
14th January 2015, 08:01
Unfortunately I didn`t succeed in bringing downloaded data to the class mainWidget for drawing.

You can emit the data as part of a signal and connect it to a matching slot in this "mainWidget" class.

Cheers,
_

dolin93
16th January 2015, 12:01
Thanks for Your answers!
In my program there are now the header files (abbreviated)
class FileDownloader : public QObject
{
Q_OBJECT
public:
FileDownloader(const QUrl &KUrl);
virtual ~FileDownloader();
QByteArray downloadedData() const;

signals:
void downloaded();
void DataA(const QByteArray&);

public slots:
void fileDownloaded(QNetworkReply* pReply);
private:
QUrl kUrl;
QNetworkAccessManager m_WebCtrl;
QByteArray m_DownloadedData;
};
class mainWidget : public QWidget
{
Q_OBJECT
public:
mainWidget();
public slots:
void Receiver(const QByteArray &QBA);
protected:
void paintEvent(QPaintEvent *event);
private:
QByteArray A;
};and the source files
FileDownloader::FileDownloader( const QUrl &KUrl) : kUrl(KUrl)
{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(fileDownloaded(QNetworkReply*)));
QNetworkRequest request(kUrl);
m_WebCtrl.get(request);
}

FileDownloader::~FileDownloader()
{
}
void FileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
pReply->deleteLater();
emit downloaded();
emit DataA(m_DownloadedData);
mainWidget *mW=new mainWidget();
connect(SIGNAL(DataA(const QByteArray&)),mW,
SLOT(Receiver(const QByteArray &QBA)));
}
mainWidget::mainWidget()
{
setWindowTitle ( "paintEvent - Demo");
resize( 1000, 400 );
}
void mainWidget::paintEvent ( QPaintEvent * event ) {
QPainter painter(this);
painter.begin( this );
painter.setPen( QPen(Qt::black, 2) );
painter.drawEllipse( 40, 40, 100, 100 );
painter.setPen( QPen(Qt::green, 2) );
int u,z,x1,v1,ku,ku1;
for(int i=1;i<100;i++){
u=4*i;
x1=4*i+4;
ku=CloseAdj[i+2];
ku1=CloseAdj[i+3];
painter.drawLine(u,z,x1,v1);
}
}
void mainWidget::Receiver(const QByteArray &QBA){
A=QBA;
int j=0;
while(A[j]!='2')
{j++;
}
QVector<QString> days;
QVector<float> CloseAdj;
QVector<int> Volume;
for(int i=j;i<1100;i++)
{QString day =" ";
QString volume = " ";
QString CloseAd =" ";
qint32 volume_=0;
float Close=0;
for (int k=0;k<10;k++)
{day+=A[i+k];
}
i+=9;
while(A[i]!=',')
{//qDebug(" Problem bis Komma ");
i++;
}
while(A[i+1]!=',')
{i++;}
while(A[i+2]!=',')
{i++;}
while(A[i+3]!=',')
{i++;}
while(A[i+4]!=',')
{i++;}
while(A[i+5]!=',')
{volume+=A[i+5];
i++;
}
while(((A[i+6]>='0' && A[i+6]<='9') || A[i+6]== '.')&& !(A[i+6]=='2' && A[i+7]=='0' && A[i+8]<='1' && A[i+9]<='5') )
{CloseAd+=A[i+6];
i++;
}
i+=6;
Close=CloseAd.toFloat();
days.append(day);
CloseAdj.append(Close);
volume_=volume.toInt();
Volume.append(volume_);
}
for(int l=0;l<10;l++)
{QString tag=days[l];
}
return;
}
int main(int argc, char *argv[])
{
QApplication a( argc, argv );
char separator, step='d',tags;
QString symbol="AAPL";
int startDay=20,startMonth=7,startYear=2014,endDay=17, endMonth=10,endYear=2014,sM,eM;
sM=startMonth-1;
eM=endMonth-1;
QUrl histUrl(QString("http://ichart.finance.yahoo.com/table.csv?s=%1&a=%2&b=%3&c=%4&d=%5&e=%6&f=%7&g=step&y=0&ignore=.cvs").arg(symbol).arg(sM).arg(startDay).arg(startYear) .arg(eM).arg(endDay).arg(endYear),QUrl::TolerantMo de);
mainWidget w;
w.show();
return a.exec();
}and I received the error message
Fehler:no matching function for call to 'FileDownloader::connect(const char [26], mainWidget*&, const char [33])' Can somebody the necessary changes post?

Lesiok
16th January 2015, 12:36
void FileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
pReply->deleteLater();
emit downloaded();
emit DataA(m_DownloadedData);
mainWidget *mW=new mainWidget();
connect(SIGNAL(DataA(const QByteArray&)),mW,SLOT(Receiver(const QByteArray &QBA)));
}
Are you sure you know what you're doing ? First, send a signal DataA() (line 6) and then create the recipient (line 7).
In general, in such a situation you do not need signals and slots. You can transfer the data directly as a parameter to the constructor class mainWidget.

anda_skoa
16th January 2015, 13:44
In your main() function you create a mainWidget and show it, which is very reasonable.

But neither main() nor the mainWidget create a FileDownloader.

My suggestion would be to create the FileDownloader in mainWidget and also set up the connection between the downloader and the widget right there.

Cheers,
_

dolin93
17th January 2015, 23:04
Thanks for Your answers!
At first I tried in vain to transfer the downloaded data without connect to mainWidget and then used connect in mainWidget
class mainWidget : public QWidget
{
Q_OBJECT
public:
mainWidget(const QUrl &Urlh);
public slots:
void Receiver(const QByteArray &QBA);
protected:
void paintEvent(QPaintEvent *event);
};
mainWidget::mainWidget(const QUrl &Urlh):histUrl(Urlh)
{
setWindowTitle ( "paintEvent - Demo");
resize( 1000, 400 );
FileDownloader demo(histUrl);
connect(SIGNAL(DataA(const QByteArray&)),demo,
SLOT(Receiver(const QByteArray &QBA)));
}



void mainWidget::paintEvent ( QPaintEvent * event ) {
QPainter painter(this);
painter.begin( this );
painter.setPen( QPen(Qt::black, 2) );
painter.drawEllipse( 40, 40, 100, 100 );
painter.drawLine(0,200,80,200);
painter.drawLine(340,200,800,200);
painter.setPen(
QPen(Qt::black, 5, Qt::DotLine, Qt::RoundCap));
//painter.drawRect( 160, 40, 120, 150 );
painter.setPen( QPen(Qt::green, 2) );
int u,x1,ku,ku1;
for(int i=1;i<8;i++)
{
u=10*i;
x1=15*i;
ku=CloseAdj[i+2];
ku1=CloseAdj[i+7];
painter.drawLine(u,ku,x1,ku1);
}

}
void mainWidget::Receiver(const QByteArray &QBA){
A=QBA;
int j=0;
while(A[j]!='2')
{j++;
}
QVector<QString> days;
QVector<float> CloseAdj;
QVector<int> Volume;
for(int i=j;i<1100;i++)
{QString day =" ";
QString volume = " ";
QString CloseAd =" ";
qint32 volume_=0;
float Close=0;
for (int k=0;k<10;k++)
{day+=A[i+k];
}
i+=9;
while(A[i]!=',')
{//qDebug(" Problem bis Komma ");
i++;
}
while(A[i+1]!=',')
{i++;}
while(A[i+2]!=',')
{i++;}
while(A[i+3]!=',')
{i++;}
while(A[i+4]!=',')
{i++;}
while(A[i+5]!=',')
{volume+=A[i+5];
i++;
}
while(((A[i+6]>='0' && A[i+6]<='9') || A[i+6]== '.')&& !(A[i+6]=='2' && A[i+7]=='0' && A[i+8]<='1' && A[i+9]<='5') )
{CloseAd+=A[i+6];
i++;
}
i+=6;
Close=CloseAd.toFloat();
days.append(day);
CloseAdj.append(Close);
volume_=volume.toInt();
Volume.append(volume_);
}
for(int l=0;l<10;l++)
{QString tag=days[l];
}
return;
}
. The other files are
class FileDownloader : public QObject
{
Q_OBJECT
public:
FileDownloader(const QUrl &KUrl);
virtual ~FileDownloader();
signals:
void downloaded();
void DataA(m_DownloadedData);
// private slots:
public slots:
void fileDownloaded(QNetworkReply* pReply);
private:
QUrl kUrl;
QNetworkAccessManager m_WebCtrl;
QByteArray m_DownloadedData;
};
FileDownloader::FileDownloader( const QUrl &KUrl) : kUrl(KUrl)
{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
SLOT(fileDownloaded(QNetworkReply*)),downloadedDat a());
QNetworkRequest request(kUrl);
m_WebCtrl.get(request);
}

FileDownloader::~FileDownloader()
{

}

void FileDownloader::fileDownloaded(QNetworkReply* pReply)
{
m_DownloadedData = pReply->readAll();
pReply->deleteLater();
emit downloaded();
emit DataA(m_DownloadedData); and
int main(int argc, char *argv[])
{
QApplication a( argc, argv );
char separator, step='d',tags;
QString symbol="AAPL";
int startDay=20,startMonth=7,startYear=2014,endDay=17, endMonth=10,endYear=2014,sM,eM;
sM=startMonth-1;
eM=endMonth-1;
QUrl histUrl(QString("http://ichart.finance.yahoo.com/table.csv?s=%1&a=%2&b=%3&c=%4&d=%5&e=%6&f=%7&g=step&y=0&ignore=.cvs").arg(symbol).arg(sM).arg(startDay).arg(startYear) .arg(eM).arg(endDay).arg(endYear),QUrl::TolerantMo de);
QString row4;
mainWidget w(const QUrl &Urlh);
w.show();
return a.exec();. I received the error messages
/../YahooGUI1/filedownloader.h:22: Fehler:'m_DownloadedData' has not been declared
GUI1/main.cpp:26: Fehler:request for member 'show' in 'w', which is of non-class type 'mainWidget(const QUrl&)''.
The difficulties in bringing the QUrl into mainWidget were almost the same as those in transfering the downloaded data without connect into mainWidget.
I think gradually comes the time to give up.

ChrisW67
18th January 2015, 02:05
This line of main.cpp:

mainWidget w(const QUrl &Urlh);
is not what you think it is. This is a declaration of a function w() that takes a QUrl and returns a mainWidget (that function does not exist). What you are trying to do is construct a mainWidget object and provide its constructor with an argument (a QUrl value) thus:


mainWidget w(histUrl);
w.show();

This is precisely the same sort of thing you do in the mainWidget constructor when you pass the QUrl value into the FileDownloader constructor.

What is at line 22 of filedownloader.h?

Edit: Answered my own question

Line 22 of filedownloader.h must be this one:


void DataA(m_DownloadedData);

The header is a declaration not an implementation. You are declaring a function DataA(...) that returns nothing and takes an argument. The stuff in the parentheses is the type (and optionally name) of the argument. What you have supplied is a name that is unknown as a type: hence the error. What you should be doing is:


void DataA(const QByteArray &someName);

While this is a Qt signal, to C++ it is simply another function. The implementation of this function is provided by the Qt tools (moc), which is why you do not need/see this function implemented in filedownloader.cpp.


It seems that a lack of understanding of C++, not Qt, is a reasonable part of the problems here. Rather than run up a white flag perhaps taking a step back and doing some generic C++ tutorials would be useful.

anda_skoa
18th January 2015, 09:35
ChrisW67 explained the most pressing issues already, here are some more.



mainWidget::mainWidget(const QUrl &Urlh):histUrl(Urlh)
{
setWindowTitle ( "paintEvent - Demo");
resize( 1000, 400 );
FileDownloader demo(histUrl);
connect(SIGNAL(DataA(const QByteArray&)),demo,
SLOT(Receiver(const QByteArray &QBA)));
}


The third line creates a FileDownloader instance on the stack of the mainWidget constructor, it will be gone when the constructor returns.
The next line will not compile, the sender object needs to be the first argument of connect() and it needs to be a pointer.

Cheers,
_

dolin93
19th January 2015, 22:13
Thanks for Your help!
After the correction of the first 2 errors and changes in mainWidget
mainWidget::mainWidget(const QUrl &Urlh):histUrl(Urlh)
{
setWindowTitle ( "paintEvent - Demo");
resize( 1000, 400 );
}
void mainWidget::paintEvent ( QPaintEvent * event ) {
FileDownloader demo(histUrl);
connect(&demo,SIGNAL(DataA(const QByteArray&)),
SLOT(Receiver(const QByteArray &QBA)));
QPainter painter(this);
painter.begin( this );
painter.setPen( QPen(Qt::black, 2) );
painter.drawEllipse( 40, 40, 100, 100 );
painter.drawLine(0,200,80,200);
painter.drawLine(340,200,800,200);
painter.setPen(
QPen(Qt::black, 5, Qt::DotLine, Qt::RoundCap));
//painter.drawRect( 160, 40, 120, 150 );
painter.setPen( QPen(Qt::green, 2) );
int u,x1,ku,ku1;
for(int i=1;i<8;i++)
{
u=10*i;
x1=15*i;
ku=CloseAdj[i+2];
ku1=CloseAdj[i+7];
painter.drawLine(u,ku,x1,ku1);
}

}
void mainWidget::Receiver(const QByteArray &QBA){
A=QBA;
int j=0;
while(A[j]!='2')
{j++;
}
QVector<QString> days;
// QVector<float> CloseAdj;
QVector<int> Volume;
for(int i=j;i<1100;i++)
{QString day =" ";
QString volume = " ";
QString CloseAd =" ";
qint32 volume_=0;
float Close=0;
for (int k=0;k<10;k++)
{day+=A[i+k];
}
i+=9;
while(A[i]!=',')
{//qDebug(" Problem bis Komma ");
i++;
}
while(A[i+1]!=',')
{i++;}
while(A[i+2]!=',')
{i++;}
while(A[i+3]!=',')
{i++;}
while(A[i+4]!=',')
{i++;}
while(A[i+5]!=',')
{volume+=A[i+5];
i++;
}
while(((A[i+6]>='0' && A[i+6]<='9') || A[i+6]== '.')&& !(A[i+6]=='2' && A[i+7]=='0' && A[i+8]<='1' && A[i+9]<='5') )
{CloseAd+=A[i+6];
i++;
}
i+=6;
Close=CloseAd.toFloat();
days.append(day);
CloseAdj.append(Close);
volume_=volume.toInt();
Volume.append(volume_);
}
for(int l=0;l<10;l++)
{QString tag=days[l];
}
return;
}
class mainWidget : public QWidget
{
Q_OBJECT
public:
mainWidget(const QUrl &Urlh);
public slots:
void Receiver(const QByteArray&);
//void Receiver(const QByteArray &QBA);
protected:
void paintEvent(QPaintEvent *event);
QUrl histUrl;
QVector<float> CloseAdj;
QByteArray A;
}; the program is compiled without error messages and "paintEvent - Demo" is showed according to
painter.begin( this );
painter.setPen( QPen(Qt::black, 2) );
painter.drawEllipse( 40, 40, 100, 100 );
painter.drawLine(0,200,80,200);
painter.drawLine(340,200,800,200);
painter.setPen(
QPen(Qt::black, 5, Qt::DotLine, Qt::RoundCap));
//painter.drawRect( 160, 40, 120, 150 );
painter.setPen( QPen(Qt::green, 2) );
int u,x1,ku,ku1;
for(int i=1;i<8;i++)
{
u=10*i;
x1=15*i;
ku=CloseAdj[i+2];
ku1=CloseAdj[i+7];
painter.drawLine(u,ku,x1,ku1);
}
with CloseAdj[ ]=0 because filedownloader.cpp is not called and I receive the message
Object::connect: No such slot mainWidget::Receiver(const QByteArray &QBA)
QPainter::begin: Painter already active
Object::connect: No such slot mainWidget::Receiver(const QByteArray &QBA)
QPainter::begin: Painter already active. Some errors like mainWidget w(const QUrl &Urlh) or the former missing of the creation of a FileDownloader came only into the program because of the many changes and the copying of lines.

d_stranz
19th January 2015, 23:04
Do you understand what is meant in C++ by "object lifetime" or "object scope"? In the first line of your paintEvent(), you create a FileDownloader instance on the stack. As soon as your paintEvent() exits, this instance goes out of scope. Its lifetime is the duration of the paintEvent() call. Going out of scope means the object is destroyed. In Qt, any connections made using an object are disconnected when the object is destroyed. So your code creates a FileDownloader instance, connects it to a slot, and then as soon as the paintEvent exits, the instance is destroyed and the connection is broken.

So all you did was to move a stack-based instance from your constructor to the paintEvent, but you didn't change what happens as a result at all.

The error message you see is because you still have not used correct syntax in the connect() statement.



connect(&demo,SIGNAL(DataA(const QByteArray&)), SLOT(Receiver(const QByteArray &QBA))); // << WRONG

connect(&demo,SIGNAL(DataA(const QByteArray&)), SLOT(Receiver(const QByteArray & ))); // << CORRECT (except for the "&demo" part)


Please, please learn to use CODE tags when you post code. They look like this
and . (With no spaces between the [ and ]). Paste your code between them. Use the "Go Advanced" and "Preview Post" buttons to see what your post will look like before you post it.

d_stranz
21st January 2015, 00:37
Sorry, what I posted was still not correct. The connect() should look like this:



connect(&demo,SIGNAL(DataA(const QByteArray&)), SLOT(Receiver(const QByteArray &QBA))); // << WRONG

connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & ))); // << CORRECT (except for the "&demo" part)


I guess I was overwhelmed by the overwhelming number of errors.

anda_skoa
21st January 2015, 18:30
Sorry, what I posted was still not correct.
In case you are referring to the missing receiver, that was ok.
There is an overload that takes the slot after the signal, assuming "this" as the receiver:
http://doc.qt.io/qt-5/qobject.html#connect-3

Cheers,
_

dolin93
21st January 2015, 21:44
Thanks for Your answers!
Because with
FileDownloader demo(histUrl); in mainWidget::Receiver the FileDownloader were not started I changed main.cpp
int main(int argc, char *argv[])
{
QApplication a( argc, argv );
char separator, step='d',tags;
QString symbol="AAPL";
int startDay=20,startMonth=6,startYear=2014,endDay=7, endMonth=1,endYear=2015,sM,eM;
sM=startMonth-1;
eM=endMonth-1;
QUrl histUrl(QString("http://ichart.finance.yahoo.com/table.csv?s=%1&a=%2&b=%3&c=%4&d=%5&e=%6&f=%7&g=step&y=0&ignore=.cvs").arg(symbol).arg(sM).arg(startDay).arg(startYear) .arg(eM).arg(endDay).arg(endYear),QUrl::TolerantMo de);
FileDownloader demo(histUrl);
QByteArray B;
mainWidget w(B);
QObject::connect(&demo,SIGNAL(DataA(const QByteArray&)),&w,
SLOT(Receiver(const QByteArray &)));
w.show();
return a.exec();
}
and a little bit also mainWidget
mainWidget::mainWidget(const QByteArray &QBA):A(QBA) Now the program runs.

wysota
21st January 2015, 22:04
I know you are probably just a beginner but it really helps for clarify if you keep your code properly indented. Otherwise it is very hard to read.

d_stranz
25th January 2015, 19:05
Now the program runs.

Do you understand why it runs? Or did you just move code around until it finally worked?

dolin93
26th January 2015, 15:10
Thank You for Your help!
If I use an additional methode
int mainWidget::helper(QString &result){
result="Attempt";
FileDownloader demo(histUrl);
connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
return 0;
} and change
int main(int argc, char *argv[])
{
QApplication a( argc, argv );
char separator, step='d',tags;
QString symbol="AAPL";
int startDay=20,startMonth=6,startYear=2014,endDay=17, endMonth=1,endYear=2015,sM,eM;
sM=startMonth-1;
eM=endMonth-1;
QUrl histUrl(QString("http://ichart.finance.yahoo.com/table.csv?s=%1&a=%2&b=%3&c=%4&d=%5&e=%6&f=%7&g=step&y=0&ignore=.cvs").arg(symbol).arg(sM).arg(startDay).arg(startYear) .arg(eM).arg(endDay).arg(endYear),QUrl::TolerantMo de);
QString result;
mainWidget w(histUrl);
w.helper(result);
w.show();
qDebug(qPrintable(result));
return a.exec();
} there will be no calling of FileDownloader. Only with
FileDownloader demo(histUrl); in main.cpp FileDownloader were started.

anda_skoa
26th January 2015, 15:19
If I use an additional methode
int mainWidget::helper(QString &result){
result="Attempt";
FileDownloader demo(histUrl);
connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
return 0;
}
What do you think will happen to the "demo" object if the execution reaches the end of return?

Cheers,
_

jefftee
26th January 2015, 15:34
[QUOTE=dolin93;271892]

int mainWidget::helper(QString &result){
result="Attempt";
FileDownloader demo(histUrl);
connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
return 0;
}
The FileDownloader shown above is allocated on the stack and deleted as soon as you return from mainWidget::helper. When the destructor is called, any signals/slots will be disconnected for your FileDownloader, meaning your slot will never be called.

You need to allocate FileDownloader on the heap (new FileDownloader(histUrl)) or make it a class member variable.

Hope that helps.

d_stranz
26th January 2015, 20:33
I'm giving up on this one. There is such a wide gap between what we're saying and what is being understood that it just isn't worth the investment.

dolin93
13th February 2015, 22:43
Thanks for Your answers!
Also with the suggested changes
FileDownloader *demo = new FileDownloader(histUrl);
mainWidget w;
QObject::connect(demo,SIGNAL(DataA(const QByteArray&)),&w,
SLOT(Receiver(const QByteArray &)));
demo->start();
w.show(); the QByteArray is not available in mainwidget.cpp.

anda_skoa
14th February 2015, 08:00
What do you mean by that?

Is the slot not called? If so, is the signal emitted?

Throwing in some random code snippets while obviously changing all other kinds of things as well (there was no start() method in previously posted FileDownloader) doesn't allow anyone to even venture a guess what could be wrong.

Cheers,
_

dolin93
14th February 2015, 22:40
Thanks for Your answer!
After correction of a little mistake now the program works. Vielen Dank in die Steiermark!