Hi every one
I've a question to qcombobox. In my application I would add all current Serial ports to the Combo box during the runtime. I tried to update the list, when the user clicks on the Combobox (read only).
After some searching I found something:
http://www.qtcentre.org/threads/946-...from-QCombobox
But the problem is, that the Event function is never called... so where is my fault?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QQueue>
#include <QLineSeries>
#include <QSerialPortInfo>
namespace Ui {
class MainWindow;
}
{
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void vUpdatePortList();
protected:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QQueue>
#include <QLineSeries>
#include <QSerialPortInfo>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void vUpdatePortList();
protected:
bool bEventFilter(QObject* o, QEvent* e);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include <QLabel>
#include <QTimer>
#include <QChartView>
#include <QValueAxis>
#include <QLineSeries>
#include <QMessageBox>
#include <QSortFilterProxyModel>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
{
ui->setupUi(this);
const QList<QSerialPortInfo> portList(QSerialPortInfo::availablePorts());
int i = 0;
foreach (QSerialPortInfo port, portList)
{
ui->comboBoxPorts->addItem(port.portName());
ui->comboBoxPorts->setItemData(i, port.description(), Qt::ToolTipRole);
i++;
}
// Sort List
proxy->setSourceModel(ui->comboBoxPorts->model());
ui->comboBoxPorts->model()->setParent(proxy);
ui->comboBoxPorts->model()->sort(0);
ui->comboBoxPorts->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
{
{
vUpdatePortList();
ui->textEdit->append("TRUE");
return true;
}
else
{
ui->textEdit->append("FALSE");
return false;
}
}
void MainWindow::vUpdatePortList()
{
ui->textEdit->append("Hallo");
}
#include "mainwindow.h"
#include <QLabel>
#include <QTimer>
#include <QChartView>
#include <QValueAxis>
#include <QLineSeries>
#include <QMessageBox>
#include <QSortFilterProxyModel>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
{
ui->setupUi(this);
const QList<QSerialPortInfo> portList(QSerialPortInfo::availablePorts());
int i = 0;
foreach (QSerialPortInfo port, portList)
{
ui->comboBoxPorts->addItem(port.portName());
ui->comboBoxPorts->setItemData(i, port.description(), Qt::ToolTipRole);
i++;
}
// Sort List
QSortFilterProxyModel* proxy = new QSortFilterProxyModel(ui->comboBoxPorts);
proxy->setSourceModel(ui->comboBoxPorts->model());
ui->comboBoxPorts->model()->setParent(proxy);
ui->comboBoxPorts->model()->sort(0);
ui->comboBoxPorts->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::bEventFilter(QObject* o, QEvent* e)
{
if(e->type() == QEvent::Show)
{
vUpdatePortList();
ui->textEdit->append("TRUE");
return true;
}
else
{
ui->textEdit->append("FALSE");
return false;
}
}
void MainWindow::vUpdatePortList()
{
ui->textEdit->append("Hallo");
}
To copy to clipboard, switch view to plain text mode
Isn't there any Click-Signal in QT?
Thank you for helping me.
Best regards, P51D
Bookmarks