Good Morning, Evening
I am trying to get to terms with QT i am new so sorry if i ask stupid questions,
however what i am tying to accomplish i have got directory listing all the folders in a certain directory,
however once i have selected a i item i want to save i cant seem to do this as i not quite sure how to create a signal and slot for a button press and item select,
this is the code i do have so far.
.H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QListWidget>
#include <QListWidgetItem>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; class MyWidget; }
QT_END_NAMESPACE
{
Q_OBJECT
private slots:
void on_pushButton_2_clicked();
private:
Ui::MainWindow *ui;
};
{
Q_OBJECT
public:
MainWindow
(QWidget *parent
= nullptr
);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
public:
Ui::MainWindow *ui;
public:
void Pathref();
void elfentestme();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QListWidget>
#include <QListWidgetItem>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; class MyWidget; }
QT_END_NAMESPACE
class MyWidget : public QWidget
{
Q_OBJECT
MyWidget(QWidget *parent = 0);
private slots:
void itemClicked(QListWidgetItem *item);
void on_pushButton_2_clicked();
private:
QListWidget *m_myListWidget;
Ui::MainWindow *ui;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void OnItemSelected( QListWidgetItem* item );
public:
Ui::MainWindow *ui;
public:
void Pathref();
void elfentestme();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
CPP
MyWidget
::MyWidget(QWidget *parent
){
}
{
if (!item)
return;
QMessageBox::information(this,
"",m_myListWidget
->row
(item
) + item
->text
());
}
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
m_myListWidget = new QListWidget(this);
connect(ui->listWidget, SIGNAL(itemClicked(QListWidgetItem *)), SLOT(itemClicked (QListWidgetItem *)));
}
void MyWidget::itemClicked(QListWidgetItem *item)
{
if (!item)
return;
QMessageBox::information(this,"",m_myListWidget->row(item) + item->text());
}
To copy to clipboard, switch view to plain text mode
but cant seem to link button at all i looked up tutorials on YouTube and on QT Help
but cant seem to get this to work trying to select a item and then i have a button that says save and pressing that i want to save the full dir path
but for some reason it does nothing,
and am still using the mainwindow.h
and cpp
because i cant seem to get the ui reference on my own cpp and h files.
Bookmarks