Database connection working, displaying verses.
This commit is contained in:
parent
47e9e8e7a8
commit
302980f890
@ -12,6 +12,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||||
|
|
||||||
|
find_package(Qt6 REQUIRED COMPONENTS Sql)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(PROJECT_SOURCES
|
set(PROJECT_SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
@ -43,7 +47,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(Daily_Bread PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
target_link_libraries(Daily_Bread PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||||
|
target_link_libraries(Daily_Bread PRIVATE Qt6::Sql)
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
# If you are developing for iOS or macOS you should consider setting an
|
# If you are developing for iOS or macOS you should consider setting an
|
||||||
# explicit, fixed bundle identifier manually though.
|
# explicit, fixed bundle identifier manually though.
|
||||||
|
@ -11,13 +11,14 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QSqlDatabase>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
|
||||||
//Function declarations
|
//Function declarations
|
||||||
int current_day();
|
int current_day();
|
||||||
int current_month();
|
int current_month();
|
||||||
QString verse_display();
|
|
||||||
std::string verse_grab();
|
QString verse_grab();
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
@ -25,9 +26,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->verse->setText(verse_display());
|
ui->verse->setText(verse_grab());
|
||||||
std::cout << current_day();
|
|
||||||
std::cout << current_month();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -38,23 +38,7 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Function: verse_display
|
|
||||||
* description: This function asks verse_grab to get the verse from the sqlite3 database, converts it
|
|
||||||
* to a format that QT can display, and then returns it to MainWindow.
|
|
||||||
* Return type: QString
|
|
||||||
* Param: none
|
|
||||||
*/
|
|
||||||
QString verse_display()
|
|
||||||
{
|
|
||||||
std::string verse_text;
|
|
||||||
|
|
||||||
verse_text = verse_grab();
|
|
||||||
|
|
||||||
QString returned_string = QString::fromStdString(verse_text);
|
|
||||||
|
|
||||||
return returned_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,18 +47,36 @@ QString verse_display()
|
|||||||
* Return type: string
|
* Return type: string
|
||||||
* Param: none
|
* Param: none
|
||||||
*/
|
*/
|
||||||
std::string verse_grab(){
|
QString verse_grab(){
|
||||||
|
|
||||||
|
|
||||||
std::string my_verse;
|
|
||||||
|
|
||||||
//gets current month and day and returns the result
|
//gets current month and day and returns the result
|
||||||
int curmonth = current_month();
|
int curmonth = current_month();
|
||||||
int curday = current_day();
|
int curday = current_day();
|
||||||
std::string query = "select * from verses where day = " + std::to_string(curday) + " and month = " + std::to_string(curmonth);
|
std::string query_string = "select * from verse_list where day = " + std::to_string(curday) + " and month = " + std::to_string(curmonth);
|
||||||
|
QString q_query = QString::fromStdString(query_string);
|
||||||
|
|
||||||
//placeholder until I get the SQLlite3 connection working
|
QString my_verse;
|
||||||
my_verse = "hello world!";
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
|
db.setDatabaseName("./verses.sqlite");
|
||||||
|
|
||||||
|
if(db.open()){
|
||||||
|
|
||||||
|
QSqlQuery query(db);
|
||||||
|
|
||||||
|
if (query.exec(q_query)){
|
||||||
|
query.next();
|
||||||
|
|
||||||
|
my_verse = query.value(1).toString();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
return my_verse;
|
return my_verse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return "error: sqlite database missing";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<x>10</x>
|
<x>10</x>
|
||||||
<y>20</y>
|
<y>20</y>
|
||||||
<width>361</width>
|
<width>361</width>
|
||||||
<height>161</height>
|
<height>271</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -46,6 +46,9 @@
|
|||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
Loading…
Reference in New Issue
Block a user