Skip to content
  • syntax error

    Unsolved General and Desktop
    6
    0 Votes
    6 Posts
    475 Views
    JonBJ

    @a_coder
    I don't claim to understand what you are trying to achieve, but let's assume this is the way you want to go. Then I can see why the control class might need to know about the mainwindow class. But I cannot see why the latter would then need to know about the former, or what you are passing/sharing between them. If you got rid of that dependency direction you might not need your mutual references.

  • 0 Votes
    10 Posts
    842 Views
    F

    @hskoglund I tried specifying the path the way you proposed. I can now build correctly and both lines aren't instantly flagged, but rebuilding the whole project is still giving me the same issue.

    I don't know if it's related, but while trying to run the programme, it crashes and tell me that dxl_x64_cpp.dll could not be found.

    I accidently put the dll file into the MinGW debug folder rather than in the MSVC folder. I can launch the app now.

    It still give me the error mentioned in the title when I rebuild, but I no longer encounter any issue while building.

    Thank you all!

  • 0 Votes
    4 Posts
    1k Views
    T

    Hello guys,

    I'm quite often facing the same problem.
    Who to fix this problem?

  • 0 Votes
    10 Posts
    2k Views
    O

    @jsulm You were right. I finally understood what you meant by getting the db at any time. Thank you very much for your help!

    This is my working code:

    #include "f1_system.h" #include <QtSql/qsqldatabase.h> #include <QtSql/qsqlquery.h> #include <QtSql/qsqlerror.h> #include <QtSql/qsqldriver.h> F1_System::F1_System(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "dataB"); QString connectionString = "Driver={SQL Server};Server=DESKTOP-4K9MAS2\\SQLEXPRESS01;Database=Formula1_BD;Trusted_Connection=yes;"; db.setDatabaseName(connectionString); connect(ui.loginPushButton, SIGNAL(clicked()), this, SLOT(validateLogin())); } F1_System::~F1_System() { QSqlDatabase::database("dataB").close(); } void F1_System::validateLogin() { if (QSqlDatabase::database("dataB").open()) { QString selectUser("SELECT Username FROM Users WHERE Username = '" + ui.usernameInputField->text() + "' AND Userpassword = '" + ui.passwordInputField->text() + "';"); QSqlQuery qry(selectUser, QSqlDatabase::database("dataB")); if (qry.next()) ui.label->setText("Status: You are logged in!"); else ui.label->setText("Status: Wrong credentials!\nTry again!"); } else ui.label->setText("Failed to connect to the database!"); }
  • 0 Votes
    4 Posts
    5k Views
    VRoninV

    that's because there is where you need to pass the username

    employeeinfo *emp = new employeeinfo(username);

    Given the doubts you are having my advice is to take a quick look to a general C++ tutorial like http://www.cplusplus.com/doc/tutorial/ before diving into Qt

  • 0 Votes
    6 Posts
    3k Views
    SGaistS

    Just adding a header file here won't help much and you are doing it the wrong way around.

    Why should your EmployeeInfo class know anything from MainWindow ? That's only going to create a tight coupling and the time you'll want to change MainWindow for something else, you'll also have to change EmployeeInfo.

    If you are going to show EmployeeInfo from MainWindow, add setters to EmployeeInfo that you'll use to update its content before showing it like already suggested by @mjsurette or use properties/signals and slots.

  • 0 Votes
    5 Posts
    6k Views
    RedleoufR

    Indeed it did the work, it is working fine now, thank you :)

  • 0 Votes
    1 Posts
    1k Views
    No one has replied