Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在my main中调用Qt小部件主窗口函数_C++_Qt_Function_Main_Qtwidgets - Fatal编程技术网

C++ 在my main中调用Qt小部件主窗口函数

C++ 在my main中调用Qt小部件主窗口函数,c++,qt,function,main,qtwidgets,C++,Qt,Function,Main,Qtwidgets,我正在尝试在我的主函数中调用Qt Mainwindow函数,但不幸的是它不起作用 一些信息:我已经编写了一个简单的登录应用程序。下面是它的代码: void MainWindow::on_pushButton_Login_clicked() { QString username = ui->lineEdit_username->text(); QString password = ui->lineEdit_password->text(); if(username =

我正在尝试在我的主函数中调用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");
  }

}
我还有一段代码,用于将批处理文件的内容保存到向量中。 在这段代码中,我有一个查找函数,用来查找某个单词

我在这里试图实现的是1.将批处理的内容保存到我的向量中,然后使用find函数查找该向量中的某个单词,然后在找到该单词时,提示用户输入用户名和密码(这是通过我的登录应用程序完成的)

现在我的问题在这里,我有所有的代码,但我不知道如何把它放在一起,我不是C++程序员,事实上我是一个完整的NoOB。我的老板刚刚让我把这件事做完,而我正在努力:c

下面是用批处理文件的内容填充向量的代码

 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 */
intmain()
{
//变数
//文件路径,指针
const char*filePath=“C:/Users/Name/Downloads/test.bat”;
//单线
std::字符串行;
//载体
std::vector my_vec;
//文件流,读取
//std::ifstream myfile(“batch.bat”);
std::ifstream myfile(filePath);
//测试以打开文件
如果(!myfile)
{

std::cout我基本上做了一件非常愚蠢的事情,修改了main.cpp文件(在QtWidgets应用程序中)并删除了默认的main函数,如下所示

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

    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();

      return a.exec();
    }
但不幸的是,我的find函数不起作用。 我希望有一个条件语句,如果在向量中找到某个字符串元素,它将调用我的函数,使用:

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;   
if(std::find(my_vec.begin()、my_vec.end()、much)!=my_vec.end())//或“much”
w、 在按钮上单击登录();
其他的

std::您在
main
中定义了
MainWindow
类吗?正如我所看到的,您正在尝试调用
MainWindow::on_button_Login_clicked()
是静态函数,而不是静态函数。因此您需要定义类型为
MainWindow
的对象并调用此对象的函数我认为MainWindow类是在我的头文件中定义的代码如下:#ifndef MainWindow#define MainWindow#include namespace Ui{class MainWindow;}class MainWindow:public QMainWindow{Q_OBJECT public:explicit main window(QWidget*parent=0);~main window();按下按钮时无效\u Login\u clicked();Ui::main window*Ui;};\endif//main window以下是我如何做到的:if(i!=my_vec.end())//main window;但我在“.”之前得到了预期的非限定id。不要在注释中发布代码,编辑问题而不是开始删除代码,直到没有其他内容可以删除而不丢失此错误。这称为最小化。您可能会显示许多不相关的内容,甚至没有指出代码转储中的哪一行是第101行。
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;
#include "mainwindow.h"
#include <QApplication>

    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();

      return a.exec();
    }
w.on_pushButton_Login_clicked();
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;