PDA

View Full Version : connect() problem



Pawello
1st August 2012, 09:55
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



#ifndef NOWYWPIS_H
#define NOWYWPIS_H
#include <QWidget>
#include <QLabel>
QT_BEGIN_NAMESPACE
class QGroupBox;
class QComboBox;
QT_END_NAMESPACE
extern QMap<QString, QString> al;
extern QList<QString> Lista; //QMap and QList are made in another file
class NowyWpis : public QWidget
{
Q_OBJECT
public:
NowyWpis(QWidget *parent = 0);
private slots:
void Aktual();
private:
void Wybor ();
void Dane ();
QGroupBox *wybortr;
QComboBox *wybierz;
QLabel *ikona;
QString wybrany;
};
#endif // NOWYWPIS_H



nowywpis.cpp


#include <QtGui>
#include "nowywpis.h"
NowyWpis::NowyWpis(QWidget *parent)
: QWidget(parent)
{
Wybor ();
QVBoxLayout *Layout = new QVBoxLayout;
Layout->addWidget(wybortr);
setLayout(Layout);
setWindowTitle(tr("Dodaj "));
resize(800, 600);
}
void NowyWpis::Wybor ()
{
wybortr = new QGroupBox(tr("Wybor "));
QGridLayout *grid = new QGridLayout;
wybierz = new QComboBox;

extern void wypisz ();
wypisz ();
foreach (QString k, Lista)
{
wybierz->addItem(k);
}

connect(wybierz, SIGNAL(currentIndexChanged(int)),
this, SLOT(Aktual()));
grid->addWidget(wybierz, 0, 0);
grid->addWidget(ikona, 0, 1);
wybortr->setLayout(grid);
}
void NowyWpis::Aktual ()
{
wybrany =(wybierz->currentText());
ikona = new QLabel();
ikona->setAlignment(Qt::AlignBottom | Qt::AlignRight);
ikona->setPixmap(QPixmap("Obrazy/+wybrany+"asd.png"));
}

sonulohani
1st August 2012, 11:28
Because you're using the private member function outside the class.


void NowyWpis::Wybor ()

Pawello
1st August 2012, 11:53
Because you're using the private member function outside the class.


void NowyWpis::Wybor ()


If you mean that problem is because of making Wybor() private function, it's not reason of error- I made everrything in class public:


public:
NowyWpis(QWidget *parent = 0);
public slots:
void Aktual();
public:
void Wybor ();
void Dane();
QGroupBox *wybortr;
QComboBox *wybierz;
QLabel *ikona;
QString wybrany;

but it didn't solve the problem

Santosh Reddy
1st August 2012, 12:29
void NowyWpis::Wybor ()
{
wybortr = new QGroupBox(tr("Wybor "));
QGridLayout *grid = new QGridLayout;
wybierz = new QComboBox;

extern void wypisz ();
wypisz ();
foreach (QString k, Lista)
{
wybierz->addItem(k);
}

connect(wybierz, SIGNAL(currentIndexChanged(int)),
this, SLOT(Aktual()));

ikona = new QLabel(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Add this
grid->addWidget(wybierz, 0, 0);
grid->addWidget(ikona, 0, 1); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Error
wybortr->setLayout(grid);
}
void NowyWpis::Aktual ()
{
wybrany =(wybierz->currentText());
//ikona = new QLabel(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Remove this
ikona->setAlignment(Qt::AlignBottom | Qt::AlignRight);
ikona->setPixmap(QPixmap("Obrazy/+wybrany+"asd.png"));
}

You are using "ikona" before it the created

Pawello
1st August 2012, 14:31
Thank you- this solves the problem