Results 1 to 4 of 4

Thread: QT Thread Call - Issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    37
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    8

    Default QT Thread Call - Issues

    Hi,

    Please help me. I am struck-up with thread concept. Actually my problem : I want to display the cities List in the combobox. I am getting cities list from the webservice. I am using thread for update the combo box value after webserice call finished.

    Here I can call the webservice. But I couldn't get the Reply.

    … Thanks in advance.

    I am using the following code.


    MainWindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5.  
    6. CGNetwork *cgNetwork = new CGNetwork();
    7. ui->setupUi(this);
    8.  
    9. renderThread = new RenderThread(cgNetwork);
    10. renderThread->start();
    11.  
    12. connect(renderThread,SIGNAL(finished()),this,SLOT(initControls()));
    13. }
    14.  
    15. void MainWindow::initControls()
    16. {
    17. CGMainWindowUtility *pointer = CGMainWindowUtility::instance();
    18. QStringList cityitems;
    19. cityitems <<tr("All");
    20. cityitems.append(pointer->getCityList());
    21. QStringListModel *cityModel = new QStringListModel(cityitems, this);
    22. ui->cityComboBox->setModel(cityModel);
    23. }
    To copy to clipboard, switch view to plain text mode 
    RenderThread.cpp
    Qt Code:
    1. RenderThread::RenderThread(CGNetwork *cgnetwork)
    2. {
    3. cityUrl = "http://112.138.3.181/City/Cities";
    4. categoryUrl = "http://112.138.3.181/City/Categories";
    5.  
    6. }
    7. void RenderThread::run()
    8. {
    9. qDebug()<< "THREAD Started";
    10. CGNetwork *cgnetworks = new CGNetwork();
    11. cgnetworks->getCityList(cityUrl);
    12. }
    To copy to clipboard, switch view to plain text mode 
    CGNetwork.cpp
    Qt Code:
    1. void CGNetwork ::getCityList(const QUrl url)
    2. {
    3. cityGuideNetworkAccessManager = new QNetworkAccessManager(this);
    4.  
    5. qDebug()<<"connection";
    6.  
    7. connect(cityGuideNetworkAccessManager, SIGNAL(finished(QNetworkReply*)),
    8. this, SLOT(parseCityList()));
    9.  
    10.  
    11. const QNetworkRequest cityRequest(url);
    12.  
    13. cityReply= cityGuideNetworkAccessManager->get(cityRequest);
    14.  
    15. connect(cityReply, SIGNAL(error(QNetworkReply::NetworkError)),
    16. this, SLOT(slotError()));
    17.  
    18. }
    19.  
    20. void CGNetwork::parseCityList()
    21. {
    22.  
    23. qDebug()<<"Parsing";
    24. cgParser = new CGJsonParser();
    25. cgParser->CityRead(cityReply);
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Girija; 1st October 2010 at 05:15.

Similar Threads

  1. None-GUI thread call widget method cause error
    By luochen601 in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2010, 05:39
  2. Replies: 9
    Last Post: 28th November 2009, 20:31
  3. Replies: 16
    Last Post: 7th October 2009, 08:17
  4. Replies: 6
    Last Post: 29th April 2009, 18:17
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.