Results 1 to 5 of 5

Thread: connect() problem

  1. #1
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default connect() problem

    Hi,
    I've got a problem with compilation of my program. beneath I wrote file nowywpis.cpp with header- I have problem with proper use of function connect . After adding it my program to after compiling gives a result -107374181 instead of 0.
    Thanks for your help:


    nowywpis.h

    Qt Code:
    1. #ifndef NOWYWPIS_H
    2. #define NOWYWPIS_H
    3. #include <QWidget>
    4. #include <QLabel>
    5. QT_BEGIN_NAMESPACE
    6. class QGroupBox;
    7. class QComboBox;
    8. QT_END_NAMESPACE
    9. extern QMap<QString, QString> al;
    10. extern QList<QString> Lista; //QMap and QList are made in another file
    11. class NowyWpis : public QWidget
    12. {
    13. Q_OBJECT
    14. public:
    15. NowyWpis(QWidget *parent = 0);
    16. private slots:
    17. void Aktual();
    18. private:
    19. void Wybor ();
    20. void Dane ();
    21. QGroupBox *wybortr;
    22. QComboBox *wybierz;
    23. QLabel *ikona;
    24. QString wybrany;
    25. };
    26. #endif // NOWYWPIS_H
    To copy to clipboard, switch view to plain text mode 


    nowywpis.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "nowywpis.h"
    3. NowyWpis::NowyWpis(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. Wybor ();
    7. QVBoxLayout *Layout = new QVBoxLayout;
    8. Layout->addWidget(wybortr);
    9. setLayout(Layout);
    10. setWindowTitle(tr("Dodaj "));
    11. resize(800, 600);
    12. }
    13. void NowyWpis::Wybor ()
    14. {
    15. wybortr = new QGroupBox(tr("Wybor "));
    16. QGridLayout *grid = new QGridLayout;
    17. wybierz = new QComboBox;
    18.  
    19. extern void wypisz ();
    20. wypisz ();
    21. foreach (QString k, Lista)
    22. {
    23. wybierz->addItem(k);
    24. }
    25.  
    26. connect(wybierz, SIGNAL(currentIndexChanged(int)),
    27. this, SLOT(Aktual()));
    28. grid->addWidget(wybierz, 0, 0);
    29. grid->addWidget(ikona, 0, 1);
    30. wybortr->setLayout(grid);
    31. }
    32. void NowyWpis::Aktual ()
    33. {
    34. wybrany =(wybierz->currentText());
    35. ikona = new QLabel();
    36. ikona->setAlignment(Qt::AlignBottom | Qt::AlignRight);
    37. ikona->setPixmap(QPixmap("Obrazy/+wybrany+"asd.png"));
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Pawello; 1st August 2012 at 11:54.

  2. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: connect() problem

    Because you're using the private member function outside the class.
    Qt Code:
    1. void NowyWpis::Wybor ()
    To copy to clipboard, switch view to plain text mode 
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  3. #3
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: connect() problem

    Quote Originally Posted by sonulohani View Post
    Because you're using the private member function outside the class.
    Qt Code:
    1. void NowyWpis::Wybor ()
    To copy to clipboard, switch view to plain text mode 
    If you mean that problem is because of making Wybor() private function, it's not reason of error- I made everrything in class public:
    Qt Code:
    1. public:
    2. NowyWpis(QWidget *parent = 0);
    3. public slots:
    4. void Aktual();
    5. public:
    6. void Wybor ();
    7. void Dane();
    8. QGroupBox *wybortr;
    9. QComboBox *wybierz;
    10. QLabel *ikona;
    11. QString wybrany;
    To copy to clipboard, switch view to plain text mode 

    but it didn't solve the problem

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: connect() problem

    Qt Code:
    1. void NowyWpis::Wybor ()
    2. {
    3. wybortr = new QGroupBox(tr("Wybor "));
    4. QGridLayout *grid = new QGridLayout;
    5. wybierz = new QComboBox;
    6.  
    7. extern void wypisz ();
    8. wypisz ();
    9. foreach (QString k, Lista)
    10. {
    11. wybierz->addItem(k);
    12. }
    13.  
    14. connect(wybierz, SIGNAL(currentIndexChanged(int)),
    15. this, SLOT(Aktual()));
    16.  
    17. ikona = new QLabel(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Add this
    18. grid->addWidget(wybierz, 0, 0);
    19. grid->addWidget(ikona, 0, 1); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Error
    20. wybortr->setLayout(grid);
    21. }
    22. void NowyWpis::Aktual ()
    23. {
    24. wybrany =(wybierz->currentText());
    25. //ikona = new QLabel(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Remove this
    26. ikona->setAlignment(Qt::AlignBottom | Qt::AlignRight);
    27. ikona->setPixmap(QPixmap("Obrazy/+wybrany+"asd.png"));
    28. }
    To copy to clipboard, switch view to plain text mode 

    You are using "ikona" before it the created
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    Pawello (1st August 2012)

  6. #5
    Join Date
    Jul 2012
    Posts
    25
    Thanks
    10

    Default Re: connect() problem

    Thank you- this solves the problem

Similar Threads

  1. Problem with connect
    By Momergil in forum Newbie
    Replies: 8
    Last Post: 29th July 2011, 01:27
  2. connect() problem
    By harmodrew in forum Newbie
    Replies: 14
    Last Post: 5th August 2010, 17:45
  3. Connect Problem
    By nrabara in forum Newbie
    Replies: 3
    Last Post: 4th May 2009, 12:19
  4. connect problem
    By liengen in forum Newbie
    Replies: 2
    Last Post: 22nd October 2008, 16:21
  5. Problem with connect()
    By mrnor3 in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2008, 14:05

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.