Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31

Thread: Transfer of a QByteArray to main.cpp

  1. #21
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Transfer of a QByteArray to main.cpp

    Quote Originally Posted by d_stranz View Post
    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,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    d_stranz (25th January 2015)

  3. #22
    Join Date
    Jan 2015
    Posts
    12
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transfer of a QByteArray to main.cpp

    Thanks for Your answers!
    Because with
    Qt Code:
    1. FileDownloader demo(histUrl);
    To copy to clipboard, switch view to plain text mode 
    in mainWidget::Receiver the FileDownloader were not started I changed main.cpp
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a( argc, argv );
    4. char separator, step='d',tags;
    5. QString symbol="AAPL";
    6. int startDay=20,startMonth=6,startYear=2014,endDay=7, endMonth=1,endYear=2015,sM,eM;
    7. sM=startMonth-1;
    8. eM=endMonth-1;
    9. 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::TolerantMode);
    10. FileDownloader demo(histUrl);
    11. mainWidget w(B);
    12. QObject::connect(&demo,SIGNAL(DataA(const QByteArray&)),&w,
    13. SLOT(Receiver(const QByteArray &)));
    14. w.show();
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    and a little bit also mainWidget
    Qt Code:
    1. mainWidget::mainWidget(const QByteArray &QBA):A(QBA)
    To copy to clipboard, switch view to plain text mode 
    Now the program runs.

  4. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Transfer of a QByteArray to main.cpp

    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.
    Last edited by wysota; 25th January 2015 at 21:17. Reason: spelling corrections
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #24
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Transfer of a QByteArray to main.cpp

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

  6. #25
    Join Date
    Jan 2015
    Posts
    12
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transfer of a QByteArray to main.cpp

    Thank You for Your help!
    If I use an additional methode
    Qt Code:
    1. int mainWidget::helper(QString &result){
    2. result="Attempt";
    3. FileDownloader demo(histUrl);
    4. connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 
    and change
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a( argc, argv );
    4. char separator, step='d',tags;
    5. QString symbol="AAPL";
    6. int startDay=20,startMonth=6,startYear=2014,endDay=17, endMonth=1,endYear=2015,sM,eM;
    7. sM=startMonth-1;
    8. eM=endMonth-1;
    9. 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::TolerantMode);
    10. QString result;
    11. mainWidget w(histUrl);
    12. w.helper(result);
    13. w.show();
    14. qDebug(qPrintable(result));
    15. return a.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 
    there will be no calling of FileDownloader. Only with
    Qt Code:
    1. FileDownloader demo(histUrl);
    To copy to clipboard, switch view to plain text mode 
    in main.cpp FileDownloader were started.

  7. #26
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Transfer of a QByteArray to main.cpp

    Quote Originally Posted by dolin93 View Post
    If I use an additional methode
    Qt Code:
    1. int mainWidget::helper(QString &result){
    2. result="Attempt";
    3. FileDownloader demo(histUrl);
    4. connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 
    What do you think will happen to the "demo" object if the execution reaches the end of return?

    Cheers,
    _

  8. #27
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Transfer of a QByteArray to main.cpp

    [QUOTE=dolin93;271892]
    Qt Code:
    1. int mainWidget::helper(QString &result){
    2. result="Attempt";
    3. FileDownloader demo(histUrl);
    4. connect(&demo,SIGNAL(DataA(const QByteArray&)), this, SLOT(Receiver(const QByteArray & )));
    5. return 0;
    6. }
    To copy to clipboard, switch view to plain text mode 
    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.

  9. #28
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Transfer of a QByteArray to main.cpp

    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.

  10. #29
    Join Date
    Jan 2015
    Posts
    12
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transfer of a QByteArray to main.cpp

    Thanks for Your answers!
    Also with the suggested changes
    Qt Code:
    1. FileDownloader *demo = new FileDownloader(histUrl);
    2. mainWidget w;
    3. QObject::connect(demo,SIGNAL(DataA(const QByteArray&)),&w,
    4. SLOT(Receiver(const QByteArray &)));
    5. demo->start();
    6. w.show();
    To copy to clipboard, switch view to plain text mode 
    the QByteArray is not available in mainwidget.cpp.

  11. #30
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Transfer of a QByteArray to main.cpp

    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,
    _

  12. The following user says thank you to anda_skoa for this useful post:

    dolin93 (14th February 2015)

  13. #31
    Join Date
    Jan 2015
    Posts
    12
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transfer of a QByteArray to main.cpp

    Thanks for Your answer!
    After correction of a little mistake now the program works. Vielen Dank in die Steiermark!

Similar Threads

  1. Replies: 2
    Last Post: 8th August 2014, 20:08
  2. Replies: 6
    Last Post: 14th May 2014, 13:14
  3. Replies: 1
    Last Post: 22nd June 2011, 09:12
  4. Replies: 9
    Last Post: 25th July 2009, 14:27
  5. Replies: 11
    Last Post: 11th August 2008, 10:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.