记录qt的一些案例,以后方便查找
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. #ifndef MENUDIALOG_H
  2. #define MENUDIALOG_H
  3. #include <QDialog>
  4. #include <QDebug>
  5. #include <qdatetime.h>
  6. static QString getRandomString(int length) //获取指定长度的字符串
  7. {
  8. qsrand(QDateTime::currentMSecsSinceEpoch());//为随机值设定一个seed
  9. const char chrs[] = "0123456789";
  10. int chrs_size = sizeof(chrs);
  11. char* ch = new char[length + 1];
  12. memset(ch, 0, length + 1);
  13. int randomx = 0;
  14. for (int i = 0; i < length; ++i)
  15. {
  16. randomx= rand() % (chrs_size - 1);
  17. ch[i] = chrs[randomx];
  18. if(i % 8 == 0 && ch[i] == '0'){ //数字开头不能为0
  19. i = i-1;
  20. }
  21. }
  22. QString ret(ch);
  23. delete[] ch;
  24. return ret;
  25. }
  26. namespace Ui {
  27. class MenuDialog;
  28. }
  29. class MenuDialog : public QDialog
  30. {
  31. Q_OBJECT
  32. public:
  33. explicit MenuDialog(QWidget *parent = nullptr);
  34. ~MenuDialog();
  35. void uodateNumbers();
  36. void updateImage();
  37. private slots:
  38. void on_pushButton_exit_clicked();
  39. private:
  40. void initUI();
  41. Ui::MenuDialog *ui;
  42. protected:
  43. virtual void
  44. mousePressEvent(QMouseEvent *event){}; //不执行默认的事件,不然一点窗口就消失了
  45. virtual void
  46. mouseDoubleClickEvent(QMouseEvent *event){};
  47. virtual void
  48. mouseReleaseEvent(QMouseEvent *event){};
  49. };
  50. #endif // MENUDIALOG_H