Hallo beides funktioniert leider nicht
upsala hat geschrieben:
label1->setText((treeView->currentIndex()).data());
bringt
Code: Alles auswählen
Fehler: keine passende Funktion für Aufruf von »QLabel::setText(QVariant)«
und bei der Lösung von caligano
habe ich in meinem Header
der connect ist meinem constructor .
der aufruf
Code: Alles auswählen
void Klasse::copy_Slot(const QModelIndex &index)
{
QString fileName = model->fileName(index);
label1->setText(fileName);
}
ergibt
Code: Alles auswählen
Fehler: »model« wurde in diesem Gültigkeitsbereich nicht definiert
wie mache ich den model bekannt wenn nicht im construtor?
hier mal meine main
Code: Alles auswählen
#include <QApplication>
#include <QtGui>
#include "mywdg.h"
int main(int argc, char *argv[])
{ QApplication app(argc, argv);
Q_INIT_RESOURCE(mywidget);
myWDG *win = new myWDG();
win->show();
return app.exec();
};
mein widget header
Code: Alles auswählen
class myWDG : public QWidget , private Ui::myWidget
{
Q_OBJECT
public:
myWDG( );
/*$PUBLIC_FUNCTIONS$*/
private slots:
/*$PUBLIC_SLOTS$*/
virtual void multi_Slot();
virtual void combobox_Slot();
virtual void help_Slot();
virtual void delete_Slot();
virtual void move_Slot();
virtual void copy_Slot(const QModelIndex &index);
protected:
/*$PROTECTED_FUNCTIONS$*/
QProcess *proc;
QString Fpath,Ppath;
QTimer timer;
protected slots:
/*$PROTECTED_SLOTS$*/
};
hier mywdg.cpp
Code: Alles auswählen
myWDG::myWDG( ): QWidget()
{
setupUi( this );
QDirModel *model = new QDirModel;
//QTreeView *tree = new QTreeView(treeView);
treeView->setModel(model);
treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
treeView->header()->setClickable(true);
QModelIndex parentIndex = model->index(QDir::rootPath());
int numRows = model->rowCount(parentIndex);
for (int row = 0; row < numRows; ++row) {
QModelIndex index = model->index(row, 0, parentIndex);
QString text = model->data(index, Qt::DisplayRole).toString();
QString fileName = model->fileName(index);
}
treeView->setRootIndex(parentIndex);
connect(helpB, SIGNAL(clicked()), this, SLOT (help_Slot()));
connect( comboBox2, SIGNAL( activated(int) ), this, SLOT( combobox_Slot() ) );
connect( SendB, SIGNAL( clicked() ), this,SLOT( multi_Slot() ) );
connect(treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(copy_Slot(const QModelIndex &)));
connect( SendB, SIGNAL( clicked() ), this,SLOT( multi_Slot() ) );
connect( deleteB, SIGNAL( clicked() ), this, SLOT( delete_Slot() ) );
}
void myWDG::copy_Slot(const QModelIndex &index)
{
QString fileName = model->fileName(index);
textLabel1_2->setText(fileName);
}
was mache ich verkehrt was muss ich ändern ?
gruß
central
Using Qt version 4.1.4