[Qt-interest] Fwd: problem with signal of QListWidget

mierdatutis mi mmm286 at gmail.com
Sun Jun 21 11:50:19 CEST 2009


Thanks..

This is the full code:

mainwindowimpl.cpp

#include "mainwindowimpl.h"
#include <QProcess>
#include <QtGui>
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QTextEdit>
#include <QListWidgetItem>
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
connect(boton, SIGNAL(clicked()), this, SLOT(sinopsis()));
connect(lista, SIGNAL( itemClicked(QListWidgetItem*) ), this, SLOT(
cambio(QListWidgetItem*) ) );
}

void MainWindowImpl::cambio(QListWidgetItem * item )
{
QMessageBox kmsgBox;
kmsgBox.setText("The document has been modified.");
kmsgBox.exec();
}

void MainWindowImpl::sinopsis()
{
QObject *parent;
QProcess *proc = new QProcess();
proc->start("/home/david/seguridad/verdadero/sin.sh", QStringList() <<
"kkametro" );
QStringList nidea;
QFile file;
QTextEdit text;
file.setFileName( "prueba" );
QDir::setCurrent( "/home/david" );
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
QString line = in.readAll();
text.show();
QMessageBox msgBox;
msgBox.setText(line);
msgBox.exec();
}


main.cpp

#include <QApplication>
#include "mainwindowimpl.h"
#include <QDir>
#include <QTextEdit>
#include <QFileInfoList>
#include <iostream>
#include <QListWidget>
#include <QProcess>

int main(int argc, char ** argv)
{
    QApplication app( argc, argv );
    MainWindowImpl win;
    app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
    QTextEdit text;
    QDir dir;
        // QDir dir = QDir::currentPath();
        QString directorio = "/home/david/COMPLETADAS/PELIS";
        QDir listado(directorio);
        QListWidget lista;
    listado.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks);
     listado.setSorting(QDir::Size | QDir::Reversed);
        QFileInfoList list = listado.entryInfoList();
       // std::cout << qPrintable(QString(listado));
           std::cout << "     Bytes Filename" << std::endl;
     for (int i = 0; i < list.size(); ++i) {
         QFileInfo fileInfo = list.at(i);
           // QString kk = fileinfo.filename();
         std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
                                                 .arg(fileInfo.fileName()));
         std::cout << std::endl;
         text.setPlainText(QString("%1 %2").arg(fileInfo.size(), 10)
                                                 .arg(fileInfo.fileName()));

lista.insertItem(i,fileInfo.fileName());


text.setPlainText("aaaagfffddfgfdddgdfffgdfaaa");

          text.show();
          lista.show();
}

win.show();
return app.exec();

}


mainwindowimpl.h

#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
    MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
    void sinopsis();
    void cambio(QListWidgetItem*);
    };



Many thanks!!!


2009/6/20 Stephen Jackson <spjackson42 at gmail.com>

> On Sat, Jun 20, 2009 at 2:17 PM, mierdatutis mi wrote:
> > Thanks I try with "itemClicked"
> >
> > I do:
> >
> > connect(lista, SIGNAL( itemClicked(QListWidgetItem*) ), this, SLOT(
> > cambio(QListWidgetItem*)
> >
> > void MainWindowImpl::cambio(QListWidgetItem *c)
> >
> > {
> >
> > QMessageBox msgBox;
> >
> > msgBox.setText("The document has been modified.");
> >
> > msgBox.exec();
> >
> > }
> >
> > and in the h file
> >
> > class MainWindowImpl : public QMainWindow, public Ui::MainWindow
> >
> > {
> >
> > Q_OBJECT
> >
> > public:
> >
> > MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
> >
> > private slots:
> >
> > void sinopsis();
> >
> > void cambio(QListWidgetItem*);
> >
> > };
> >
> > #endif
> >
> > But doesn't works! :-(
> >
>
> The code you have shown here ought to work. The code you originally
> posted using currentItemChanged ought to work.
>
> The fault is probably in some code that you are not showing us. What
> is "lista"? Is it really a pointer to your user interface QListWidget,
> or is it just some local variable?
>
> I suggest you post a complete minimal compilable example that
> demonstrates your problem.
>
> Regards,
>
> Stephen Jackson
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090621/f52b8d44/attachment.html 


More information about the Qt-interest-old mailing list