- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的主函数中调用 Qt Mainwindow 函数,但不幸的是它不起作用
一些信息:我写了一个简单的登录应用程序。这是它的代码:
void MainWindow::on_pushButton_Login_clicked()
{
QString username = ui->lineEdit_username->text();
QString password = ui->lineEdit_password->text();
if(username == "test" && password == "test")
{
QMessageBox::information(this,"Login", "Username and password is
correct");
}
else
{
QMessageBox::warning(this,"Login", "Username and Password is not
correct");
}
}
我还有一段代码,用于将批处理文件的内容保存到 vector 中。在该代码中,我有一个查找函数,用于查找某个单词。
我在这里要实现的是 1. 将批处理的内容保存到我的 vector 中,然后让查找函数在该 vector 中查找特定单词,然后在找到该单词时提示用户输入用户名和密码(这是通过我的登录应用程序完成的)
现在这就是我的问题所在,我有所有的代码,但是我不知道如何将它们组合在一起,我不是 c++ 程序员,事实上我是一个完整的菜鸟。我的老板刚刚让我完成这件事,但我很挣扎 :c
这是用批处理文件的内容填充我的 vector 的代码
int main()
{
// VARIABLES
// file path, pointer
const char * filePath = "C:/Users/Name/Downloads/test.bat";
// single line
std::string line;
// vector
std::vector<std::string> my_vec;
// filestream, reading
//std::ifstream myfile("batch.bat");
std::ifstream myfile(filePath);
// Test to open file
if (!myfile)
{
std::cout << "Error opening file" << std::endl;
exit(1);
}
else
{
std::cout << "File opened successfully (for reading)" << std::endl;
}
// Read from file and put into vector
while (myfile) // while we are reading the file
{
getline(myfile, line);
my_vec.push_back(line);
}
//my find function
std::vector<std::string>::iterator i;
i = std::find(my_vec.begin(),my_vec.end(),"batch");
if (i != my_vec.end())
/**** here is where id like to call my clicked function ****/
/* tried putting in "void MainWindow::on_pushButton_Login_clicked()" but it
here's what I got */
1.错误:对 qMain(int, char**) 的 undefined reference 和 collect2.exe:-1: error: error: ld returned 1 exit status
else
std::cout<<"No result found" << std::endl;
// Close filestream
myfile.close();
return 0;
}
如果这个问题太具体或非常愚蠢,我深表歉意,但我只是需要帮助,但我找不到任何关于这样一个具体问题的信息,而且所有可能有帮助的东西都是为那些真正了解自己的人提供的重新使用 C++
我将不胜感激任何贡献!
Bearded beaver:我的 MainWindow 类在我的 mainwindow.H 头文件中定义我将其包含在我的 main.cpp 文件中
这是 Mainwindow.h 文件中的代码
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void on_pushButton_Login_clicked();
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
这是我在上面的查找函数中输入的内容
std::vector<std::string>::iterator i;
i = std::find(my_vec.begin(),my_vec.end(),"much");
if (i != my_vec.end())
MainWindow.on_pushButton_Login_clicked();
else
std::cout<<"No result found" << std::endl;
这是我得到的错误
main.cpp:101: 错误:'.' 前应为非限定 ID token MainWindow.on_pushButton_Login_clicked(); ^
感谢您抽出时间!
最佳答案
我基本上做了一些非常愚蠢的事情,通过改变 main.cpp 文件(在 Qt Widgets 应用程序中)并删除看起来像这样的默认主函数
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
因为声明了对象名称,所以我需要它来调用我在 MainWindow 类中的函数。像这样:
w.on_pushButton_Login_clicked();
不幸的是,我的查找功能不起作用。如果在我的 vector 中找到某个字符串元素,我想有一个条件语句调用我的函数:
if (std::find(my_vec.begin(),my_vec.end(),much) != my_vec.end() ) //or "much"
w.on_pushButton_Login_clicked();
else
std::cout<<"No result found" << std::endl;
我没有收到任何错误,它只是提示我登录应用程序,而不管是否找到了元素。
我不知道为什么会这样,但如果我发现了,我会编辑这个答案^^谢谢大家花时间,如果我使用了错误的术语/措辞,请提前道歉。
关于c++ - 在我的主窗口中调用 Qt 小部件主窗口函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538898/
我听说过两种数据库架构。 大师级 主从 master-master不是更适合现在的web吗,因为它就像Git一样,每个单元都有整套数据,如果一个宕机也无所谓。 主从让我想起了 SVN(我不喜欢它),你
我们当前将 MySQL 配置为支持故障转移:Site1 Site2。当它们被设置为主/主时。在给定时间点,应用程序服务器仅主动写入一个站点。我们想要设置一个新的故障转移站点。然后我们将拥有 Site
我听说过两种数据库架构。 大师-大师 主从 master-master 不是更适合当今的网络吗,因为它就像 Git,每个单元都有整套数据,如果其中一个发生故障,也没关系。 主从让我想起 SVN(我不喜
我正在创建一个标记为类别的表,其中主类别(父列)包含 0,子类别包含父类别的 ID。我听说这叫引用。我的问题:这张表的结构正确吗?或者是否有更好的方法,例如实现遍历树或类似方法? CREATE TAB
我正在阅读一份关于 C++ 与 C 的文档。该文档说与 C 相比,C++ 编写得非常紧凑。一个例子是,C 允许 main() 函数类型为 void。另一方面,C++ 不允许这样做,他给出了标准中的以下
C main函数和Java main函数有什么区别? int main( int argc, const char* argv[] ) 对比 public static void main(Strin
我一直摸不着头脑,但运气不好。设计器有一个包含 3 栏的站点、两个侧边栏和一个主要内容区域。 专为桌面设计,左栏、主要内容、右栏。但是,在较小的设备上,我们希望首先堆叠主要内容。 所以通常情况下,你可
我一直在阅读有关 Jenkins 主/从配置的信息,但我仍然有一些问题: 是不是真的没有像 Jenkins 主站那样安装和启动从站 Jenkins?我假设我会以相同的方式安装一个主 Jenkins 和
据我了解,Viemodel中MVVM背后的概念包括业务逻辑和/或诸如暴露于 View 的数据的主/明细关系之类的事物 因此,正如我发现的那样,有很多ORM生成器,例如模型的telerik a.o以及另
我们有一个群集,其中包含3个主分区,每个主分区有2个副本。主/副本分片的总文档数相同;但是,对于同一查询/文档,我们得到3个不同的分数。当我们将preference = primary添加为查询参数时
我有一个非常大/旧/长时间运行的项目,它使用相对于启动目录的路径访问文件资源(即应用程序仅在从特定目录启动时才工作)。当我需要调试程序时,我可以从 eclipse 启动它并使用“运行配置”->->“工
谁能向我解释一下为什么我在这段代码上遇到段错误?我一直试图弄清楚这一点,但在各种搜索中却一无所获。当我运行代码而不调用 main(argc, argv) 时,它会运行。 Slave 仅将 argv 中
使用 xcode 中的默认项目作为主从应用程序,如果我在折叠委托(delegate)中放置 print 调试语句,当我旋转设备时它似乎永远不会被触发(事实上我永远无法触发它)。 我编辑的代码位于 Ap
是否有任何产品可以使 mysql 主/从故障转移过程更容易?一些可以自动发生的事情,而不是手动修复它。 最佳答案 [...稍后...;) 你所说的“更容易”是什么?MySQL 有很多解决方案: MyS
我有两个 mysql 数据库。我想做主/主复制。 复制以一种方式进行。然而,反过来说却不然。该错误表明它无法与用户“test@IPADDRESS”连接。 如何将用户名更改为 repl?从未进行过测试,
我正在尝试在 MySQL 中运行以下查询: GRANT REPLICATION SLAVE ON *.* TO 'replication'@’10.141.2.%’ IDENTIFIED BY ‘sl
我正在尝试使用 Android 提供的主/详细流程模板创建一个应用程序,并且我正在尝试将多个操作栏菜单项添加到操作栏的主要部分和详细信息部分。这就是我要实现的目标: (来源:softwarecrew.
我正在寻找一个跨平台的 C++ master/worker 库或工作队列库。一般的想法是我的应用程序将创建某种任务或工作对象,将它们传递给工作主机或工作队列,这将依次在单独的线程或进程中执行工作。为了
我似乎看到很多人在他们的 MySQL 模式中任意分配大尺寸的主/外键字段,例如 INT(11) 甚至 WordPress 使用的 BIGINT(20)。 如果我错了,请纠正我,但即使是 INT(4)
如果我有一个可以与多个键相关联的用户,正确的表设置应该是: 一个表有两列,例如: UserName | Key 没有主键且用户可以有多行,或者: 具有匹配标识符的两个表 Table 1 Us
我是一名优秀的程序员,十分优秀!