第三章 创建主窗口

2023-11-20

创建一个主窗口,具有菜单、工具栏、状态栏和对话框之类的界面和功能。实现电子制表软件的主窗口框架。

效果:



mainwindow.h
头文件就不做太多解释,以注释的方式解释函数
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAction>
#include <QLabel>
#include <QFileDialog>
#include <QMessageBox>
#include <QStatusBar>
#include <QToolBar>
#include <QMenu>
#include <QMenuBar>
#include "spreadsheet.h"
#include "finddialog.h"

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow();

protected:
	//是Qwidget类中的一个虚函数,当用户关闭这个窗口时会被自动调用诶,可以在里面做自己想做的事情。
    void closeEvent(QCloseEvent *event);

private slots:
	//声明了很多槽函数,作为窗口的功能菜单项和其中子菜单项 File->New这种的。    
	//File
	void newFile();
    void open();
    bool save();
    bool saveAs();
    void openRecentFile();
	//close()

	//Edit
    void find();
    void goToCell();

	//Tools
    void sort();

	//Help
    void about();

	//
    void updateStatusBar();
    void spreadsheetModified();

private:
    //私有函数实现菜单功能
    void createActions();
    void createMenus();
    void createContextMenu();
    void createToolBars();
    void createStatusBar();
    void readSettings();
    void writeSettings();
    bool okToContinue();
    bool loadFile(const QString &fileName);
    bool saveFile(const QString &fileName);
    void setCurrentFile(const QString &fileName);
    void updateRecentFileActions();
    QString strippedName(const QString &fullFileName);

    Spreadsheet *spreadsheet;
    FindDialog *findDialog;
    QLabel *locationLabel;
    QLabel *formulaLabel;
    QStringList recentFiles;
    QString curFile;

    enum { MaxRecentFiles = 5 };
    QAction *recentFileActions[MaxRecentFiles];
    QAction *separatorAction;

    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *selectSubMenu;
    QMenu *toolsMenu;
    QMenu *optionsMenu;
    QMenu *helpMenu;
    QToolBar *fileToolBar;
    QToolBar *editToolBar;
    QAction *newAction;
    QAction *openAction;
    QAction *saveAction;
    QAction *saveAsAction;
    QAction *exitAction;
    QAction *cutAction;
    QAction *copyAction;
    QAction *pasteAction;
    QAction *deleteAction;
    QAction *selectRowAction;
    QAction *selectColumnAction;
    QAction *selectAllAction;
    QAction *findAction;
    QAction *goToCellAction;
    QAction *recalculateAction;
    QAction *sortAction;
    QAction *showGridAction;
    QAction *autoRecalcAction;
    QAction *aboutAction;
    QAction *aboutQtAction;
};
#endif


mainwindow.cpp
1)先来看构造函数
MainWindow::MainWindow()
{
	//先创建一个Spreadsheet表格窗口部件并且设置为中央窗口
    spreadsheet = new Spreadsheet;
    setCentralWidget(spreadsheet);

	//相当于初始化窗口,createXXXX创建窗口中的其他部分
    createActions();
    createMenus();
    createContextMenu();
    createToolBars();
    createStatusBar();
    
    readSettings();

    findDialog = 0;
    setWindowIcon(QIcon("images/icon.png"));
    setCurrentFile("");
}

把findDialog初始化为空,在第一次调用find()时再创建该对象;

这里没有采用Qt的资源机制来加载图片;

2)创建菜单和工具栏
void MainWindow::createActions()
{
	//创建File->New
    newAction = new QAction(tr("&New"), this);
    newAction->setIcon(QIcon("images/new.png"));
    newAction->setShortcut(QKeySequence::New);
    newAction->setStatusTip(tr("Create a new spreadsheet file"));
    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
	//创建File->Open
	openAction = new QAction(tr("&Open..."), this);
    openAction->setIcon(QIcon("images/open.png"));
    openAction->setShortcut(QKeySequence::Open);
    openAction->setStatusTip(tr("Open an existing spreadsheet file"));
    connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
	//创建File->Save
	saveAction = new QAction(tr("&Save"), this);
    saveAction->setIcon(QIcon("images/save.png"));
    saveAction->setShortcut(QKeySequence::Save);
    saveAction->setStatusTip(tr("Save the spreadsheet to disk"));
    connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
	//创建File->SaveAs
    saveAsAction = new QAction(tr("Save &As..."), this);
    saveAsAction->setStatusTip(tr("Save the spreadsheet under a new name"));
    connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
	//创建File->recentFileActions 最近打开文件,检测最近最多的五个
    for (int i = 0; i < MaxRecentFiles; ++i) 
	{
        recentFileActions[i] = new QAction(this);
        recentFileActions[i]->setVisible(false);//创建了但是不显示
        connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile()));
    }
	//创建File->Exit
	exitAction = new QAction(tr("E&xit"), this);
    exitAction->setShortcut(tr("Ctrl+Q"));
    exitAction->setStatusTip(tr("Exit the application"));
    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
	//创建Edit->Cut
    cutAction = new QAction(tr("Cu&t"), this);
    cutAction->setIcon(QIcon("images/cut.png"));
    cutAction->setShortcut(QKeySequence::Cut);
    cutAction->setStatusTip(tr("Cut the current selection's contents to the clipboard"));
    connect(cutAction, SIGNAL(triggered()), spreadsheet, SLOT(cut()));
	//创建Edit->Copy
	copyAction = new QAction(tr("&Copy"), this);
    copyAction->setIcon(QIcon("images/copy.png"));
    copyAction->setShortcut(QKeySequence::Copy);
    copyAction->setStatusTip(tr("Copy the current selection's contents to the clipboard"));
    connect(copyAction, SIGNAL(triggered()), spreadsheet, SLOT(copy()));
	//创建Edit->Paste
	pasteAction = new QAction(tr("&Paste"), this);
    pasteAction->setIcon(QIcon("images/paste.png"));
    pasteAction->setShortcut(QKeySequence::Paste);
    pasteAction->setStatusTip(tr("Paste the clipboard's contents into the current selection"));
    connect(pasteAction, SIGNAL(triggered()), spreadsheet, SLOT(paste()));
	//创建Edit->Delete
    deleteAction = new QAction(tr("&Delete"), this);
    deleteAction->setShortcut(QKeySequence::Delete);
    deleteAction->setStatusTip(tr("Delete the current selection's contents"));
    connect(deleteAction, SIGNAL(triggered()), spreadsheet, SLOT(del()));
	//创建Edit->Select->Row
    selectRowAction = new QAction(tr("&Row"), this);
    selectRowAction->setStatusTip(tr("Select all the cells in the current row"));
    connect(selectRowAction, SIGNAL(triggered()), spreadsheet, SLOT(selectCurrentRow()));
	//创建Edit->Select->Column
    selectColumnAction = new QAction(tr("&Column"), this);
    selectColumnAction->setStatusTip(tr("Select all the cells in the current column"));
    connect(selectColumnAction, SIGNAL(triggered()), spreadsheet, SLOT(selectCurrentColumn()));
	//创建Edit->Select->All
    selectAllAction = new QAction(tr("&All"), this);
    selectAllAction->setShortcut(QKeySequence::SelectAll);
    selectAllAction->setStatusTip(tr("Select all the cells in the spreadsheet"));
    connect(selectAllAction, SIGNAL(triggered()), spreadsheet, SLOT(selectAll()));
	//创建Edit->Find
	findAction = new QAction(tr("&Find..."), this);
    findAction->setIcon(QIcon("images/find.png"));
    findAction->setShortcut(QKeySequence::Find);
    findAction->setStatusTip(tr("Find a matching cell"));
    connect(findAction, SIGNAL(triggered()), this, SLOT(find()));
	//创建Edit->Go To Cell
    goToCellAction = new QAction(tr("&Go to Cell..."), this);
    goToCellAction->setIcon(QIcon("images/gotocell.png"));
    goToCellAction->setShortcut(tr("Ctrl+G"));
    goToCellAction->setStatusTip(tr("Go to the specified cell"));
    connect(goToCellAction, SIGNAL(triggered()), this, SLOT(goToCell()));
	//创建Tools->Recalculate
    recalculateAction = new QAction(tr("&Recalculate"), this);
    recalculateAction->setShortcut(tr("F9"));
    recalculateAction->setStatusTip(tr("Recalculate all the spreadsheet's formulas"));
    connect(recalculateAction, SIGNAL(triggered()), spreadsheet, SLOT(recalculate()));
	//创建Tools->Sort
    sortAction = new QAction(tr("&Sort..."), this);
    sortAction->setStatusTip(tr("Sort the selected cells or all the cells"));
    connect(sortAction, SIGNAL(triggered()), this, SLOT(sort()));
	//创建Options->Show Grid
    showGridAction = new QAction(tr("&Show Grid"), this);
    showGridAction->setCheckable(true);
    showGridAction->setChecked(spreadsheet->showGrid());
    showGridAction->setStatusTip(tr("Show or hide the spreadsheet's grid"));
    connect(showGridAction, SIGNAL(toggled(bool)), spreadsheet, SLOT(setShowGrid(bool)));

#if QT_VERSION < 0x040102
    // workaround for a QTableWidget bug in Qt 4.1.1
    connect(showGridAction, SIGNAL(toggled(bool)),
            spreadsheet->viewport(), SLOT(update()));
#endif

	//创建Options->Auto-Recalculate
	autoRecalcAction = new QAction(tr("&Auto-Recalculate"), this);
    autoRecalcAction->setCheckable(true);
    autoRecalcAction->setChecked(spreadsheet->autoRecalculate());
    autoRecalcAction->setStatusTip(tr("Switch auto-recalculation on or off"));
    connect(autoRecalcAction, SIGNAL(toggled(bool)), spreadsheet, SLOT(setAutoRecalculate(bool)));
	//创建Help->About
	aboutAction = new QAction(tr("&About"), this);
    aboutAction->setStatusTip(tr("Show the application's About box"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
	//创建Help->About Qt
	aboutQtAction = new QAction(tr("About &Qt"), this);
    aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}

就是为了创建菜单
*创建并设置动作; 

    newAction = new QAction(tr("&New"), this);
    newAction->setIcon(QIcon(":/images/new.png"));
    newAction->setShortcut(QKeySequence::New);
    newAction->setStatusTip(tr("Create a new spreadsheet file"));
    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

*创建菜单并添加动作到菜单;

    editMenu = menuBar()->addMenu(tr("&Edit"));
    editMenu->addAction(cutAction);
    editMenu->addAction(copyAction);
    editMenu->addAction(pasteAction);
    editMenu->addAction(deleteAction);

*创建工具栏并添加动作到工具栏。

    fileToolBar = addToolBar(tr("&File"));
    fileToolBar->addAction(newAction);
    fileToolBar->addAction(openAction);
    fileToolBar->addAction(saveAction);



3)创建一级菜单

void MainWindow::createMenus()
{
	//创建一级菜单
    fileMenu = menuBar()->addMenu(tr("&File"));
    fileMenu->addAction(newAction);
    fileMenu->addAction(openAction);
    fileMenu->addAction(saveAction);
    fileMenu->addAction(saveAsAction);
    separatorAction = fileMenu->addSeparator();
    for (int i = 0; i < MaxRecentFiles; ++i)
        fileMenu->addAction(recentFileActions[i]);
    fileMenu->addSeparator();
    fileMenu->addAction(exitAction);

    editMenu = menuBar()->addMenu(tr("&Edit"));
    editMenu->addAction(cutAction);
    editMenu->addAction(copyAction);
    editMenu->addAction(pasteAction);
    editMenu->addAction(deleteAction);

    selectSubMenu = editMenu->addMenu(tr("&Select"));
    selectSubMenu->addAction(selectRowAction);
    selectSubMenu->addAction(selectColumnAction);
    selectSubMenu->addAction(selectAllAction);

    editMenu->addSeparator();
    editMenu->addAction(findAction);
    editMenu->addAction(goToCellAction);

    toolsMenu = menuBar()->addMenu(tr("&Tools"));
    toolsMenu->addAction(recalculateAction);
    toolsMenu->addAction(sortAction);

    optionsMenu = menuBar()->addMenu(tr("&Options"));
    optionsMenu->addAction(showGridAction);
    optionsMenu->addAction(autoRecalcAction);

    menuBar()->addSeparator();

    helpMenu = menuBar()->addMenu(tr("&Help"));
    helpMenu->addAction(aboutAction);
    helpMenu->addAction(aboutQtAction);
}


4)

void MainWindow::createToolBars()
{
	//创建工具按钮
    fileToolBar = addToolBar(tr("&File"));
    fileToolBar->addAction(newAction);
    fileToolBar->addAction(openAction);
    fileToolBar->addAction(saveAction);

    editToolBar = addToolBar(tr("&Edit"));
    editToolBar->addAction(cutAction);
    editToolBar->addAction(copyAction);
    editToolBar->addAction(pasteAction);
    editToolBar->addSeparator();
    editToolBar->addAction(findAction);
    editToolBar->addAction(goToCellAction);
}


5)

void MainWindow::createStatusBar()
{
	//设置状态栏
	locationLabel = new QLabel(" W999 ");
	locationLabel->setAlignment(Qt::AlignHCenter);
	locationLabel->setMinimumSize(locationLabel->sizeHint());

	formulaLabel = new QLabel;
	formulaLabel->setIndent(3);

	statusBar()->addWidget(locationLabel);
	statusBar()->addWidget(formulaLabel, 1);

	connect(spreadsheet, SIGNAL(currentCellChanged(int, int, int, int)), this, SLOT(updateStatusBar()));
	connect(spreadsheet, SIGNAL(modified()), this, SLOT(spreadsheetModified()));

	updateStatusBar();
}


void MainWindow::updateStatusBar()
{
	//更新单元格指示器,因为SpreadSheet不会一开始就发射改变的消息所以需要spreadsheetModified()
    locationLabel->setText(spreadsheet->currentLocation());
    formulaLabel->setText(spreadsheet->currentFormula());
}

void MainWindow::spreadsheetModified()
{
    setWindowModified(true);
    updateStatusBar();
}



6)菜单功能的实现

void MainWindow::newFile()
{
    if (okToContinue()) 
	{
        spreadsheet->clear();
        setCurrentFile("");
    }
}

void MainWindow::open()
{
    if (okToContinue())
	{
        QString fileName = QFileDialog::getOpenFileName(this, tr("Open Spreadsheet"), ".", tr("Spreadsheet files (*.sp)"));
        if (!fileName.isEmpty())
            loadFile(fileName);
    }
}

bool MainWindow::save()
{
    if (curFile.isEmpty()) 
	{
        return saveAs();
    } 
	else 
	{
        return saveFile(curFile);
    }
}

bool MainWindow::saveAs()
{
    QString fileName = QFileDialog::getSaveFileName(this,  tr("Save Spreadsheet"), ".", tr("Spreadsheet files (*.sp)"));
    if (fileName.isEmpty())
        return false;
    return saveFile(fileName);
}

void MainWindow::find()
{
    if (!findDialog) 
	{
        findDialog = new FindDialog(this);
        connect(findDialog, SIGNAL(findNext(const QString &,
                                            Qt::CaseSensitivity)),
                spreadsheet, SLOT(findNext(const QString &,
                                           Qt::CaseSensitivity)));
        connect(findDialog, SIGNAL(findPrevious(const QString &,
                                                Qt::CaseSensitivity)),
                spreadsheet, SLOT(findPrevious(const QString &,
                                               Qt::CaseSensitivity)));
    }

    findDialog->show();
    findDialog->raise();
    findDialog->activateWindow();
}

void MainWindow::goToCell()
{
    GoToCellDialog dialog(this);
    if (dialog.exec()) {
        QString str = dialog.lineEdit->text().toUpper();
        spreadsheet->setCurrentCell(str.mid(1).toInt() - 1,
                                    str[0].unicode() - 'A');
    }
}

void MainWindow::sort()
{
    SortDialog dialog(this);
    QTableWidgetSelectionRange range = spreadsheet->selectedRange();
    dialog.setColumnRange('A' + range.leftColumn(),
                          'A' + range.rightColumn());

    if (dialog.exec()) 
	{
        SpreadsheetCompare compare;
        compare.keys[0] =
              dialog.primaryColumnCombo->currentIndex();
        compare.keys[1] =
              dialog.secondaryColumnCombo->currentIndex() - 1;
        compare.keys[2] =
              dialog.tertiaryColumnCombo->currentIndex() - 1;
        compare.ascending[0] =
              (dialog.primaryOrderCombo->currentIndex() == 0);
        compare.ascending[1] =
              (dialog.secondaryOrderCombo->currentIndex() == 0);
        compare.ascending[2] =
              (dialog.tertiaryOrderCombo->currentIndex() == 0);
        spreadsheet->sort(compare);
    }
}

void MainWindow::about()
{
    QMessageBox::about(this, tr("About Spreadsheet"),
            tr("<h2>Spreadsheet 1.1</h2>"
               "<p>Copyright &copy; 2008 Software Inc."
               "<p>Spreadsheet is a small application that "
               "demonstrates QAction, QMainWindow, QMenuBar, "
               "QStatusBar, QTableWidget, QToolBar, and many other "
               "Qt classes."));
}

void MainWindow::openRecentFile()
{
    if (okToContinue()) 
	{
        QAction *action = qobject_cast<QAction *>(sender());
        if (action)
            loadFile(action->data().toString());	//打开选中的最近的文件
    }
}


7)

void MainWindow::createContextMenu()
{
    spreadsheet->addAction(cutAction);
    spreadsheet->addAction(copyAction);
    spreadsheet->addAction(pasteAction);
    spreadsheet->setContextMenuPolicy(Qt::ActionsContextMenu);
}

void MainWindow::readSettings()
{
    QSettings settings("Software Inc.", "Spreadsheet");

    restoreGeometry(settings.value("geometry").toByteArray());

    recentFiles = settings.value("recentFiles").toStringList();
    updateRecentFileActions();

    bool showGrid = settings.value("showGrid", true).toBool();
    showGridAction->setChecked(showGrid);

    bool autoRecalc = settings.value("autoRecalc", true).toBool();
    autoRecalcAction->setChecked(autoRecalc);
}

void MainWindow::writeSettings()
{
    QSettings settings("Software Inc.", "Spreadsheet");

    settings.setValue("geometry", saveGeometry());
    settings.setValue("recentFiles", recentFiles);
    settings.setValue("showGrid", showGridAction->isChecked());
    settings.setValue("autoRecalc", autoRecalcAction->isChecked());
}

bool MainWindow::okToContinue()
{
	//是否修改过、是否允许保存等判定
    if (isWindowModified()) 
	{
        int r = QMessageBox::warning(this, tr("Spreadsheet"),
                        tr("The document has been modified.\n"
                           "Do you want to save your changes?"),
                        QMessageBox::Yes | QMessageBox::No
                        | QMessageBox::Cancel);
        if (r == QMessageBox::Yes) 
		{
            return save();
        } else if (r == QMessageBox::Cancel) {
            return false;
        }
    }
    return true;
}

bool MainWindow::loadFile(const QString &fileName)
{
    if (!spreadsheet->readFile(fileName)) {
        statusBar()->showMessage(tr("Loading canceled"), 2000);
        return false;
    }

    setCurrentFile(fileName);
    statusBar()->showMessage(tr("File loaded"), 2000);
    return true;
}

bool MainWindow::saveFile(const QString &fileName)
{
    if (!spreadsheet->writeFile(fileName)) {
        statusBar()->showMessage(tr("Saving canceled"), 2000);
        return false;
    }

    setCurrentFile(fileName);
    statusBar()->showMessage(tr("File saved"), 2000);
    return true;
}

void MainWindow::setCurrentFile(const QString &fileName)
{
    curFile = fileName;
    setWindowModified(false);

    QString shownName = tr("Untitled");
    if (!curFile.isEmpty()) {
        shownName = strippedName(curFile);
        recentFiles.removeAll(curFile);
        recentFiles.prepend(curFile);
        updateRecentFileActions();
    }

    setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Spreadsheet")));
}

void MainWindow::updateRecentFileActions()
{
    QMutableStringListIterator i(recentFiles);
    while (i.hasNext()) 
	{
        if (!QFile::exists(i.next()))
            i.remove();
    }

    for (int j = 0; j < MaxRecentFiles; ++j) {
        if (j < recentFiles.count()) {
            QString text = tr("&%1 %2")
                           .arg(j + 1)
                           .arg(strippedName(recentFiles[j]));
            recentFileActions[j]->setText(text);
            recentFileActions[j]->setData(recentFiles[j]);
            recentFileActions[j]->setVisible(true);
        } else {
            recentFileActions[j]->setVisible(false);
        }
    }
    separatorAction->setVisible(!recentFiles.isEmpty());
}

QString MainWindow::strippedName(const QString &fullFileName)
{
    return QFileInfo(fullFileName).fileName();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
    if (okToContinue()) 
	{
        writeSettings();
        event->accept();
    } 
	else 
	{
        event->ignore();
    }
}


8)程序启动界面

就好像PS打开时会有一个图片显示几秒加载一些东西的时候

main.cpp

#include <QApplication>
#include <QSplashScreen>
#include <QDateTime>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
	QSplashScreen *splash = new QSplashScreen;
	splash->setPixmap(QPixmap("images/qtStart.png"));
	splash->show();

	/*使程序在显示启动画面的同时仍能响应鼠标等其他事件*/
	app.processEvents();

	Qt::Alignment topRight = Qt::AlignRight | Qt::AlignLeft;
	splash->showMessage(QObject::tr("正在启动程序..."), topRight, Qt::white);
	
    MainWindow mainWin;

	splash->showMessage(QObject::tr("发现二次元,正在扫描..."), topRight, Qt::white);

	//loadModules();

	splash->showMessage(QObject::tr("最后一步..."), topRight, Qt::white);
	
	//establishConnections();

	QDateTime n = QDateTime::currentDateTime();
	QDateTime now;
	do {
		now = QDateTime::currentDateTime();
		app.processEvents();
	} while (n.secsTo(now) <= 2);//5为需要延时的秒数

	mainWin.show();

	splash->finish(&mainWin);
	delete splash;

    return app.exec();
}


本文还未完,在实现表格后台功能后才行,在下一章继续..



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

第三章 创建主窗口 的相关文章

  • 当其源是 https uri 时如何使 wpf MediaElement 播放

    在 wpf 独立应用程序 exe 中 我在主窗口中包含了 MediaElement
  • C# 和月历,选择多个日期

    我正在制作一个程序 可以帮助人们用 C 为某个部门 预订 订单 他们需要能够选择不同月份的多个日期 我更愿意拥有它 这样他们就可以单击一个日期 然后按住 Shift 键单击另一个日期以选择这两个日期之间的所有日期 并控制单击以进行单选 取消
  • OpenGL缓冲区更新[重复]

    这个问题在这里已经有答案了 目前我正在编写一个模拟水的程序 以下是我所做的步骤 创建水面 平面 创建VAO 创建顶点缓冲区对象 在其中存储法线和顶点 将指针绑定到此 VBO 创建索引缓冲区对象 然后我使用 glDrawElements 渲染
  • 为什么在 C++ 中声明枚举时使用 typedef?

    我已经很多年没有写过任何 C 了 现在我正试图重新开始 然后我遇到了这个并考虑放弃 typedef enum TokenType blah1 0x00000000 blah2 0X01000000 blah3 0X02000000 Toke
  • 具有多个谓词的 C++11 算法

    功能如std find if来自algorithmheader 确实很有用 但对我来说 一个严重的限制是我只能为每次调用使用 1 个谓词count if 例如给定一个像这样的容器std vector我想同时应用相同的迭代find if 多个
  • DataGridView 列中的数字文本框

    我有一个DataGridView 我想要它的第一列或任何所需的列 其中有textboxes在其中 成为NUMERIC ONLY 我目前正在使用这段代码 private void dataGridViewItems EditingContro
  • 为什么 C# 中同一类型的隐式和显式运算符不能共存? [复制]

    这个问题在这里已经有答案了 为什么同一类中两个相同类型的运算符 显式和隐式 不能共存 假设我有以下内容 public class Fahrenheit public float Degrees get set public Fahrenhe
  • 类中是否可以有虚拟类声明?

    我正在为个人项目中框架的各个组件设置一个接口 我突然想到了一些我认为可能对接口有用的东西 我的问题是这是否可能 class a public virtual class test 0 class b public a public clas
  • 从时间列表中查找最接近的时间

    所以 这是场景 我有一个带有创建时间的文件 我想从该文件的创建时间最接近或相等的时间列表中选择一个时间 完成此操作的最佳方法是什么 var closestTime listOfTimes OrderBy t gt Math Abs t fi
  • R 中使用 `UseMethod()` 与 `inherits()` 来确定对象的类

    如果我需要根据 R 对象的类以不同的方式处理它们 我可以使用if and else在单个函数内 foo lt function x if inherits x list Foo the list else if inherits x num
  • make_shared<>() 中的 WKWYL 优化是否会给某些多线程应用程序带来惩罚?

    前几天我偶然看到这个非常有趣的演示 http channel9 msdn com Events GoingNative GoingNative 2012 STL11 Magic Secrets作者 Stephan T Lavavej 其中提
  • 虚拟并行端口模拟器

    在我的计算机网络课程中 我们应该通过使用本机寄存器 例如使用 outportb 等命令 来学习并行端口编程 我没有并行端口 因为我住在 2011 年 但想练习这些程序 我使用 dosbox 安装了旧的 Turboc 3 IDE 有没有一个程
  • 检测 TextBox 中的 Tab 键按下

    I am trying to detect the Tab key press in a TextBox I know that the Tab key does not trigger the KeyDown KeyUp or the K
  • “没有合适的默认构造函数可用”——为什么会调用默认构造函数?

    我已经查看了与此相关的其他一些问题 但我不明白为什么在我的情况下甚至应该调用默认构造函数 我可以只提供一个默认构造函数 但我想了解它为什么这样做以及它会产生什么影响 error C2512 CubeGeometry no appropria
  • 是否可以在Linux上将C转换为asm而不链接libc?

    测试平台为Linux 32位 但也欢迎 Windows 32 位上的某些解决方案 这是一个c代码片段 int a 0 printf d n a 如果我使用 gcc 生成汇编代码 gcc S test c 然后我会得到 movl 0 28 e
  • MSChart 控件中的自定义 X/Y 网格线

    我有一个带有简单 2D 折线图的 C Windows 窗体 我想向其中添加自定义 X 或 Y 轴标记 并绘制自定义网格线 例如 以突出显示的颜色 虚线 我查看了 customLabels 属性 但这似乎覆盖了我仍然想显示的默认网格 这是为了
  • C 与 C++ 中的 JNI 调用不同?

    所以我有以下使用 Java 本机接口的 C 代码 但是我想将其转换为 C 但不知道如何转换 include
  • 在 C++ 代码 gdb 中回溯指针

    我在运行 C 应用程序时遇到段错误 在 gdb 中 它显示我的一个指针位置已损坏 但我在应用程序期间创建了 10 万个这样的对象指针 我怎样才能看到导致崩溃的一个 我可以在 bt 命令中执行任何操作来查看该指针的生命周期吗 谢谢 鲁奇 据我
  • 选择 asp.net CheckBoxList 中的所有项目

    ASP NET 和 C 我想要一个带有 全选 项目的复选框列表 当这个特定项目是 已选择 所有其他都将被选择 也 当选择被删除时 这个项目 也将来自所有人 其他物品 选中 取消选中 任何其他项目只会有一个 对特定项目的影响 无论选择状态如何
  • 测验;这个编译了吗?如果是的话它会返回什么(我知道答案)

    我最近发现这个错字 if name find string npos 显然开发者的意思是输入 if name find string npos 但令我惊讶的是发现错误甚至编译 Wall Werror 没有尝试过 pedantic 那么 咖啡

随机推荐

  • 机器学习-线性回归-多元梯度下降法

    目录标题 线性回归 多元线性回归 正规方程 线性回归 我们的回归方程常写成如下形式 h x 0 1 X 代价函数 J 12 i 1m h x i y i 2 看看代价函数到底是在干什么 如图 梯度下降是一个用来求函数最小值的算法 我们将使用
  • Echarts-折线图-设置线条颜色以及线条以下区域显示渐变颜色

    首先 先看折线图效果 1 设置线条颜色 在series中 数组项设置lineStyle属性 lineStyle 设置线条的style等 normal color red 折线线条颜色 红色 2 设置线条上点的颜色 也是图例的颜色 在seri
  • [OpenAirInterface实战-1] :什么是OAI?OAI常见问题解答

    作者主页 文火冰糖的硅基工坊 文火冰糖 王文兵 的博客 文火冰糖的硅基工坊 CSDN博客 本文网址 https blog csdn net HiWangWenBing article details 120490410 目录 前言 什么是软
  • 上拉加载原理

    实现思路 之前写过一篇触底加载 经过一番苦学钻研 优化一下 样式方面 滚动区域是给固定高度 设置 overflow y auto 来实现 接下来看看js方面的实现 其实也很简单 触发的条件是 可视高度 滚动距离 gt 实际高度 例子我会使用
  • 网络工程师学习笔记-------关于T1和E1载波

    关于T和E载波 标准模拟话音信号频率为4KHz 为了对模拟语音进行数字化 必须按至少8KHz的速率采样 采用7Bit进行量化即128级量化 则每个信道的比特率为 8KHz 7Bit 56Kb s 为了每一个这样的低速信道安装一条通信线路是不
  • 机器学习F1值的概念

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 文章目录 一 什么是F1 score 二 计算过程 1 首先定义以下几个概念 2 通过第一步的统计值计算每个类别下的precision和recall 3 通过第二步计算结果计
  • openstack-nova-compute.service起不来

    1 启动服务 2 查看compute nova日志tail var log nova nova compute log 发现身份验证机制AMQPLAIN拒绝登录 3 关闭防火墙 root controller systemctl stop
  • 资讯汇总230217

    230217 22 48 美联储理事鲍曼 美国通胀仍旧太高 美联储理事鲍曼表示 美国通胀仍旧太高 美国当前的经济数据不一致 不同寻常的低失业率是一个好迹象 让通胀回到目标还有很长的路要走 需要继续加息 直到看到更多进展 财联社 230217
  • 西门子PLC如何与多个三菱PLC建立无线通信?

    对一个大型工厂 由于生产线的不断改造 新老流程的不断更新 这些PLC系统往往是由不同的制造商提供的 那么在智慧工厂的实现中 常会遇到不同品牌PLC之间需要进行相互通讯的情况 由于场地和生产能效的原因 在后期的系统改造中 通常需要采用无线的方
  • 构建流式应用—RxJS详解

    最近在 Alloyteam Conf 2016 分享了 使用RxJS构建流式前端应用 会后在线上线下跟大家交流时发现对于 RxJS 的态度呈现出两大类 有用过的都表达了 RxJS 带来的优雅编码体验 未用过的则反馈太难入门 所以 这里将结合
  • Oracle块损坏处理(MOS)

    处理 Oracle 块损坏 文档 ID 1526911 1 适用于 Oracle Database Enterprise Edition 版本 7 0 16 0 到 11 2 0 2 0 发行版 7 0 到 11 2 本文档所含信息适用于所
  • 微信小程序 如何返回上一个页面并实现刷新

    转载地址 https blog csdn net u011088792 article details 87938213 删除或编辑 之后返回 上一级并刷新 var pages getCurrentPages var beforePage
  • R语言实现RMF模型

    RMF模型说明 RMF模型是客户管理中 常被用来衡量客户价值和客户创利能力的重要方法 它主要考量三个指标 最近一次消费 Recency 近期购买的客户倾向于再度购买 消费频率 Frequency 经常购买的客户再次购买概率高 消费金额 Mo
  • 8年测试经验分享 —— 从0铸造测试技术壁垒

    前言 相信所有从事着软件测试或相关工作的同学都会思考一个问题 如何在持续且部分重复的测试活动中有效的进行测试技术积累 这个有趣的问题我先不予回答 我们先谈谈如何有效保证软件质量 作为团队中的质量保证者 需要深刻的意识到 验证系统原有功能是否
  • oracle 12c recover table恢复单表

    在 Oracle 12c 之前 如果误删一张表 常规的方法是 Flashback 闪回或 TSPITR 如果需要恢复的表空间过大 TSPITR 会耗时非常久 而开启 flashback 会消耗磁盘空间 在 12C 中oracle提供一个新功
  • java接口的详解

    文章目录 接口 1 1 接口的概念 1 2 接口语法规则 1 3 接口使用 1 4 接口特性 1 5 实现多个接口 1 6 接口间的继承 1 7 特殊的接口 1 7 1 Comparable接口实现compareTo方法 1 7 2 Com
  • 5. 一线大厂高并发缓存架构实战与性能优化

    分布式缓存技术Redis 1 冷热数据分离 2 缓存设计 2 1 缓存击穿 失效 2 2 缓存穿透 2 3 缓存雪崩 3 大V直播带货导致线上商品系统崩溃原因分析 4 突发性热点缓存重建导致系统压力暴增问题 5 缓存数据库双写不一致问题 6
  • pytest+UI自动化测试结果回填到excel并发送excel测试报告邮件

    现在写的脚本是web UI自动化 这个和接口自动化区别非常大 没法像接口那样请求 返回 校验结果 UI自动化 一个用例跑下来 是页面 页面 页面 完成 这样 但是还是想实现一种结果回填到excel中 看测试结果就直接看excel就可以了 一
  • WPF 路径动画PathAnimations的使用

    在wpf中让一个控件按照一定的路径运行的动画 叫做路径动画 这个示例演示了让一个rectangle按照一个s形曲线反复运行的动画 效果 只有一个文件 全部代码如下
  • 第三章 创建主窗口

    创建一个主窗口 具有菜单 工具栏 状态栏和对话框之类的界面和功能 实现电子制表软件的主窗口框架 效果 mainwindow h 头文件就不做太多解释 以注释的方式解释函数 ifndef MAINWINDOW H define MAINWIN