Unsolved Button on MS Windows taskbar
-
@zumma said:
I don't know how can i attach picture in post
Upload the picture to https://postimage.org/ and then insert it here with
![alternate text](url)
. -
from gimp -
@zumma Have a look at this example: http://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html. Should provide you with a good starting point.
-
@Wieland It's look good. I think it will be good for me. Early answers about system try icon will help me too. Thanks all. Maybe someone have one idea more :) so I'll wait with the closing topic.
-
Ok your idea was great :)
Now i have problem with connect signal and slot. I don't know what is wrong. I spent four hour on this and nothing. I think this is little mistake but i don't know where :) Problem is described in comment in code.
Next question is ... instruction "foreach" is good for this menu? It's working fine but maybe is better way to do it. Here i want to add name of files to menu. I will change this slot on mediaplayer - > play.
It's my first project in QT so be understanding.ShapedClock::ShapedClock(QWidget *parent) : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint) { QSettings setting("MyApp","mysettings"); setting.beginGroup("SettingsWindow"); QDir dir(setting.value("sciezka","C:/").toString()); setting.endGroup(); int index = 0; foreach (QFileInfo var, dir.entryInfoList()) { if(var.isFile()) { index++; QString aaa = QString::number(index); QAction *exitAction = new QAction((aaa+ ". " + var.baseName()), this); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); addAction(exitAction); } } QAction *exitAction = new QAction(tr("E&xit"), this); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); addAction(exitAction); //i can't open new window "settings" -> error: No such slot shapedClock::OpenSettings() QAction *awer = new QAction(tr("S&ettings"), this); connect(awer, SIGNAL(triggered()), this, SLOT(OpenSettings())); addAction(awer); ///// setContextMenuPolicy(Qt::ActionsContextMenu); setToolTip(tr("abcdefgh\n" "abcdefgh")); setWindowTitle(tr("nnnnnnnn")); } // ........ // ........ // ........ void ShapedClock::OpenSettings() // OpenSettings is in protected group in ShapedClock.h { SettingsDialog settingsDialog; settingsDialog.setModal(true); settingsDialog.exec(); }
-
OpenSettings() should not be under protected:
public slots:
void OpenSettings() ;
All signals must declare under
signals
and slots underslots
. -
Btw: You should use the new connect syntax as it has better compile-time checks:
connect(exitAction, &QAction::triggered, qApp, &QApplication::quit);
-
Again you are very helpful. I searched network about my new problem and nothing.
FilesDialog::FilesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::FilesDialog) { ui->setupUi(this); QSettings setting("MyApp","mysettings"); // load settings from QSettings setting.beginGroup("SettingsWindow"); QDir dir( setting.value("path","C:/").toString() ); QListWidgetItem fav ( setting.value("favorite").toString() ); setting.endGroup(); // end of loading foreach (QFileInfo var, dir.entryInfoList()) // additems to QListWidget { if(var.isFile()) ui->listWidget_files->addItem(var.fileName()); } ui->listWidget_files->setCurrentItem(&fav); // I think here is mistake or ui->listWidget_files->currentItem()->setIcon(QIcon(":/pictures/button.png")); // here }
I want to load "favorite"(It's name of item) from settings and set icon item in QListWidget.
Compilation of the project was succesfully. But when i open this window i get error and no responses. -
Hi,
Your fav object is allocated on the stack so at the end of the function it will be destroyed.
-
I think fav is in one function. When i use qQebug() i see in console "1", "-1" , and i dont see "2" because here is error. I dont know why i got "-1" when i indicate on second item.
ui->listWidget_files->setCurrentItem(&ulub); qDebug() << "1"; // work qDebug() << ui->listWidget_files->currentRow(); // -1 ui->listWidget_files->currentItem()->setIcon(QIcon(":/pictures/button.png")); qDebug() << "2";
-
@zumma As @SGaist said: you pass pointer to a local variable which is destroyed as soon as FilesDialog() finishes:
FilesDialog::FilesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::FilesDialog) { ... QListWidgetItem fav ( setting.value("favorite").toString() ); // fav is local variable and only exists in FilesDialog() ... ui->listWidget_files->setCurrentItem(&fav); // Here you pass a pointer ... } // Here fav is destoyed and the pointer you passed to setCurrentItem becomes invalid
-
@zumma Put a break point at
ui->listWidget_files->currentItem()->setIcon(QIcon(":/pictures/button.png"));
and check whether it really crash at that line.
-
To add to @jsulm, you should check that the item returned by currentItem is not null before doing anything with it.